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

sql error: Number of query values and destination fields are not the same.

P: 9
Hi. I am developing an application program in java. I use MsAccess for keeping data.

I had a problem with sql insert method.


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

I get this sql error.

[error]

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Number of query values and destination fields are not the same.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java :3111)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcSt atement.java:338)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Jdbc OdbcStatement.java:288)
at Screen.AddPatient(Screen.java:211)
at __SHELL28.run(__SHELL28.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at bluej.runtime.ExecServer$3.run(ExecServer.java:858 )

[/error]
Sep 17 '07 #1
Share this Question
Share on Google+
2 Replies


FishVal
Expert 2.5K+
P: 2,653
Hi, there.

To the best of my knowledge VALUES list should be delimited with commas, not pluses.
Sep 17 '07 #2

MMcCarthy
Expert Mod 10K+
P: 14,534
I think + is the concatenation operator. However, you will need the commas and you need to keep the variables outside the quotes. You will also have to use single quotes on those fields which are text and if any are dates such as b_day then you will have to use #. Something like the following:

sql="INSERT INTO PatientDB (PatientID,Name,Surname,Phoneno,Dateofbirth,Compla int)VALUES(" + no + ", '" + f_name + "', '" + l_name + "', " + phone + ", #" + b_day + "#, '" + text + "')";
Sep 18 '07 #3

Post your reply

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