By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,103 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

sql: problem with matching data types

P: 9
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.getInteger' in expression.
[\error]
Sep 18 '07 #1
Share this Question
Share on Google+
1 Reply


Scott Price
Expert 100+
P: 1,384
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO PatientDB ([PatientID],[Name],[Surname],[Phoneno],[Dateofbirth],[Complaint]) VALUES ( numberinput.getInteger(),nameinput.getText( ),surnameinput.getText(),phoneinput.getInteger(),d ateofbirthinput.getInteger(),tet.getText())";
It's not a data type problem, just a syntax problem in the Insert Into query, making a reference to a variable, etc with closing ()'s makes Access look for a function in a vba code module. I'm not an expert on the way your refer to controls or variables in Java, but it looks like that is what you are trying to do.

Here is an example from a test db of mine that shows correct syntax for vba, you'll have to explore a little more on the Java side of things to find out how to make those references in Java, take a look at our Java forum for more specific help there:

Expand|Select|Wrap|Line Numbers
  1. MySQL = "INSERT INTO tblTimeDiff ([TransID], [TimeDiff]) VALUES ('" & Temp1 & "','" & Temp2 & "');"
It takes the variable Temp1 and concatenates it's value into the TransID field, and the Temp2 variable likewise into the TimeDiff field.

Regards,
Scott
Sep 18 '07 #2

Post your reply

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