473,396 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sql error: data types

Hi. I want to insert data to ms access from an application I developed in java but I think I have a prob with data types.

This is my code.
[code]

savebutton.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con= DriverManager.getConnection(url);

String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values(numberinput.getInteger(),nameinput.getText( ),surnameinput.getText(),phoneinput.getInteger(),d ateofbirthinput.getInteger(),text.getText())";
PreparedStatement pstmt = con.prepareStatement(sqlStatement);
pstmt.executeUpdate();


con.close();


}

catch(ClassNotFoundException ex)
{}


catch(SQLException ex)
{
ex.printStackTrace();
}

}
});
[\code]





[error]

Hi. I want to insert data to ms access but I think I have a prob with data types.

This is my code.
[code]

savebutton.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con= DriverManager.getConnection(url);

String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values(numberinput.getInteger(),nameinput.getText( ),surnameinput.getText(),phoneinput.getInteger(),d ateofbirthinput.getInteger(),tet.getText())";
PreparedStatement pstmt = con.prepareStatement(sqlStatement);
pstmt.executeUpdate();


con.close();


}

catch(ClassNotFoundException ex)
{}


catch(SQLException ex)
{
ex.printStackTrace();
}

}
});
[\code]





[error]

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Undefined function 'numberinput.getText' in expression.
[\error]
[\error]
Sep 19 '07 #1
15 2119
madhoriya22
252 100+
Hi. I want to insert data to ms access from an application I developed in java but I think I have a prob with data types.

This is my code.
[code]

savebutton.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con= DriverManager.getConnection(url);

String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values(numberinput.getInteger(),nameinput.getText( ),surnameinput.getText(),phoneinput.getInteger(),d ateofbirthinput.getInteger(),text.getText())";
PreparedStatement pstmt = con.prepareStatement(sqlStatement);
pstmt.executeUpdate();


con.close();


}

catch(ClassNotFoundException ex)
{}


catch(SQLException ex)
{
ex.printStackTrace();
}

}
});
[\code]





[error]

Hi. I want to insert data to ms access but I think I have a prob with data types.

This is my code.
[code]

savebutton.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con= DriverManager.getConnection(url);

String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values(numberinput.getInteger(),nameinput.getText( ),surnameinput.getText(),phoneinput.getInteger(),d ateofbirthinput.getInteger(),tet.getText())";
PreparedStatement pstmt = con.prepareStatement(sqlStatement);
pstmt.executeUpdate();


con.close();


}

catch(ClassNotFoundException ex)
{}


catch(SQLException ex)
{
ex.printStackTrace();
}

}
});
[\code]





[error]

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Undefined function 'numberinput.getText' in expression.
[\error]
[\error]
Hi,
Please use code tags while posting code. It makes it readable for other people.
Check your query. They way you are calling functions to get values inside query is wrong.
Sep 19 '07 #2
dmjpro
2,476 2GB
Use Code Tags.
I think your Query string will be like this.

Expand|Select|Wrap|Line Numbers
  1.  
  2. String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir th,Complaint) values("+numberinput.getInteger()+",'"+nameinput.getText( )+"','"+surnameinput.getText()+"',"+phoneinput.getInteger()+","+d ateofbirthinput.getInteger()+",'"+tet.getText()+"')";
  3.  
It will be something like this.

Good Luck.

Kind regards,
Dmjpro.
Sep 19 '07 #3
Hi,
Please use code tags while posting code. It makes it readable for other people.
Check your query. They way you are calling functions to get values inside query is wrong.


I couldnt figure out what is wrong.Please can you write.


Expand|Select|Wrap|Line Numbers
  1. String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES(numberinput.getInteger(),nameinput.getText(),surnameinput.getText(),phoneinput.getInteger(),dateofbirthinput.getInteger(),text.getText())";
Sep 19 '07 #4
dmjpro
2,476 2GB
I couldnt figure out what is wrong.Please can you write.


Expand|Select|Wrap|Line Numbers
  1. String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES(numberinput.getInteger(),nameinput.getText(),surnameinput.getText(),phoneinput.getInteger(),dateofbirthinput.getInteger(),text.getText())";

What is this?
Expand|Select|Wrap|Line Numbers
  1. numberinput.getInteger()
  2.  
Please explain me this!
What is numberinput and getInteger?
Please let me know!

Kind regards,
Dmjpro.
Sep 19 '07 #5
What is this?
Expand|Select|Wrap|Line Numbers
  1. numberinput.getInteger()
  2.  
Please explain me this!
What is numberinput and getInteger?
Please let me know!

Kind regards,
Dmjpro.

I have an application form with five textfields.

I use numberinput: variable name for textfield for PatientID( PRİMARY KEY)
nameinput : Name(Text)
surnameinput: Surname(Text)
phonenoinput Phone(Number)
Complaint for textpane Complaint( Memo)



I
Sep 19 '07 #6
dmjpro
2,476 2GB
I have an application form with five textfields.

I use numberinput: variable name for textfield for PatientID( PRİMARY KEY)
nameinput : Name(Text)
surnameinput: Surname(Text)
phonenoinput Phone(Number)
Complaint for textpane Complaint( Memo)



I
So numberinput is your Java variable and getInteger is of it's Member method to retrieve the Integer Number the user inputs.
Right?
I assumed that I posted a solution look above.
And try this and let me know what happens!
:)

Kind regards,
Dmjpro.
Sep 19 '07 #7
So numberinput is your Java variable and getInteger is of it's Member method to retrieve the Integer Number the user inputs.
Right?
I assumed that I posted a solution look above.
And try this and let me know what happens!
:)

Kind regards,
Dmjpro.

I already use [code] numberinput.getInteger [\code]


What I dont understand is why I get this error.


[error]Undefined function 'numberinput.getText' in expression. [/error]
Sep 19 '07 #8
dmjpro
2,476 2GB
I already use [code] numberinput.getInteger [\code]


What I dont understand is why I get this error.


[error]Undefined function 'numberinput.getText' in expression. [/error]
Hello!
Try this one then let me know whether it errors or not!
:)

Expand|Select|Wrap|Line Numbers
  1. String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir   th,Complaint) values("+numberinput.getInteger()+",'"+nameinput.getText( )+"','"+surnameinput.getText()+"',"+phoneinput.getInteger()+","+d ateofbirthinput.getInteger()+",'"+tet.getText()+"')";
  2.  
And read the Posting Guidelines while you do Post.
Good Luck with your Try. :)

Kind regards,
Dmjpro.
Sep 19 '07 #9
Hello!
Try this one then let me know whether it errors or not!
:)

Expand|Select|Wrap|Line Numbers
  1. String sqlStatement = "insert into PatientDB(PatientID,Name,Surname,Phoneno,Dateofbir   th,Complaint) values("+numberinput.getInteger()+",'"+nameinput.getText( )+"','"+surnameinput.getText()+"',"+phoneinput.getInteger()+","+d ateofbirthinput.getInteger()+",'"+tet.getText()+"')";
  2.  
And read the Posting Guidelines while you do Post.
Good Luck with your Try. :)

Kind regards,
Dmjpro.

I tried it before but it didnt work. I think it is used with Statement. Here I use PreparedStatement so quotes are not needed.
And please can you tell me ( ",' ") what are these quotes used for?
Sep 19 '07 #10
dmjpro
2,476 2GB
I tried it before but it didnt work. I think it is used with Statement. Here I use PreparedStatement so quotes are not needed.
And please can you tell me ( ",' ") what are these quotes used for?
What it says when you use my Query String?
And try with simple Statement interface.
Good Luck.

Kind regards,
Dmjpro.
Sep 19 '07 #11
What it says when you use my Query String?
And try with simple Statement interface.
Good Luck.

Kind regards,
Dmjpro.

Using quotes creates more confusion. I had compilation errors.
So I took a different approach. ı used conversion methods.

I want to convert PatientID and phone fields ( numberinput and phoneinput).

So I used the method below.


Expand|Select|Wrap|Line Numbers
  1.  
  2. public void AddPatient()
  3.          {
  4.             int i=Integer.parseInt(numberinput.getText()); 
  5.  
  6.                           try{
  7.  
  8.          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  9.  
  10.            con= DriverManager.getConnection(url);
  11.  
  12. String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES(i,nameinput.getText(),surnameinput.getText(),phoneinput.getInteger(),dateofbirthinput.getInteger(),text.getText())";
  13. PreparedStatement pstmt = con.prepareStatement(sqlStatement);
  14.  
  15.  
  16.  
  17.            con.close();
  18.  
  19.  
  20.          }
  21.  
  22.       catch(ClassNotFoundException e)
  23.                {}
  24.  
  25.  
  26.         catch(SQLException ex)
  27.         {
  28.         ex.printStackTrace();
  29.         }
  30.  
  31.     }  
  32. }
  33.  
  34.  
  35.  

Then I got this error.

[ERROR]

va.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
[/ERROR]
Sep 19 '07 #12
dmjpro
2,476 2GB
Look!

suppose you have a five variables.
Expand|Select|Wrap|Line Numbers
  1. int a,b,c;
  2. String d,e;
  3. String str_qty = "insert into table_name(AA,BB,CC,DD,EE) values("+a+","+b+","+c+",'"+d+"',"+e+"')";
  4. //Now check this code again.
  5. //In SQL or Oracle the String should be separated with '' and numbers are not.
  6.  
And your NumberFormatException comes because of invalid String.
As for example 123g this String can't be parsed as Integer.
And here is your Empty String, that's why such Error comes up.

Kind regards,
Dmjpro.
Sep 19 '07 #13
Look!

suppose you have a five variables.
Expand|Select|Wrap|Line Numbers
  1. int a,b,c;
  2. String d,e;
  3. String str_qty = "insert into table_name(AA,BB,CC,DD,EE) values("+a+","+b+","+c+",'"+d+"',"+e+"')";
  4. //Now check this code again.
  5. //In SQL or Oracle the String should be separated with '' and numbers are not.
  6.  
And your NumberFormatException comes because of invalid String.
As for example 123g this String can't be parsed as Integer.
And here is your Empty String, that's why such Error comes up.

Kind regards,
Dmjpro.

I did as you said. I still get errors. I was getting undefined function errors 'nameinput.getText' and now I get insert syntax error.
Expand|Select|Wrap|Line Numbers
  1.  
  2. public void AddPatient()
  3.          {
  4.  
  5.  
  6.  
  7.             try{
  8.  
  9.          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  10.  
  11.            con= DriverManager.getConnection(url);
  12.  
  13. String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES("+numberinput.getText()+",'"+nameinput.getText()+"','"+surnameinput.getText()+"',"+phoneinput.getText()+","+dateofbirth.getText()+"'"+textpane.getText()+"')";
  14.       st= con.createStatement();
  15.  
  16.         st.execute(sqlStatement);
  17.  
  18.            con.close();
  19.  
  20.  
  21.  
Sep 19 '07 #14
madhoriya22
252 100+
I did as you said. I still get errors. I was getting undefined function errors 'nameinput.getText' and now I get insert syntax error.
Expand|Select|Wrap|Line Numbers
  1.  
  2. public void AddPatient()
  3. {
  4.  
  5.  
  6.  
  7. try{
  8.  
  9.      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  10.  
  11.      con= DriverManager.getConnection(url);
  12.  
  13. String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES("+numberinput.getText()+",'"+nameinput.getText()+"','"+surnameinput.getText()+"',"+phoneinput.getText()+","+dateofbirth.getText()+"'"+textpane.getText()+"')";
  14. st= con.createStatement();
  15.  
  16. st.execute(sqlStatement);
  17.  
  18.      con.close();
  19.  
  20.  
  21.  
Hi,
I will again suggest you to check your query. It is wrong. Check the quotes(') you have put in the query. they are not matching.
Sep 19 '07 #15
dmjpro
2,476 2GB
I did as you said. I still get errors. I was getting undefined function errors 'nameinput.getText' and now I get insert syntax error.
Expand|Select|Wrap|Line Numbers
  1.  
  2. public void AddPatient()
  3.          {
  4.  
  5.  
  6.  
  7.             try{
  8.  
  9.          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  10.  
  11.            con= DriverManager.getConnection(url);
  12.  
  13. String sqlStatement = "INSERT INTO PatientDB(PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint) VALUES("+numberinput.getText()+",'"+nameinput.getText()+"','"+surnameinput.getText()+"',"+phoneinput.getText()+","+dateofbirth.getText()+"'"+textpane.getText()+"')";
  14.       st= con.createStatement();
  15.  
  16.         st.execute(sqlStatement);
  17.  
  18.            con.close();
  19.  
  20.  
  21.  

Ok!
These type of expression I don't know you getting from.
Make sure that whether your Syntax is Ok or not.

Kind regards,
Dmjpro.
Sep 20 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Egyd Csaba | last post by:
Hi, I've a problem with some of my stored procs. My config is: RH7.1, Postgres 7.3.2 I had converted a few fields of a few tables from one type to another and after this I made all the...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
5
by: Mr. SweatyFinger | last post by:
WHY CAN'T THE CLOWN -HOLES WHO WROTE ASP.NET PROVIDE AN ERROR LINE NUMBER??? HONEST TO SH@THOLE PETE Server Error in '/New Folder (7)' Application....
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
3
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.