473,799 Members | 3,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

9 New Member
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.SQLExc eption: [Microsoft][ODBC Microsoft Access Driver] Number of query values and destination fields are not the same.
at sun.jdbc.odbc.J dbcOdbc.createS QLException(Jdb cOdbc.java:6958 )
at sun.jdbc.odbc.J dbcOdbc.standar dError(JdbcOdbc .java:7115)
at sun.jdbc.odbc.J dbcOdbc.SQLExec Direct(JdbcOdbc .java:3111)
at sun.jdbc.odbc.J dbcOdbcStatemen t.execute(JdbcO dbcStatement.ja va:338)
at sun.jdbc.odbc.J dbcOdbcStatemen t.executeUpdate (JdbcOdbcStatem ent.java:288)
at Screen.AddPatie nt(Screen.java: 211)
at __SHELL28.run(_ _SHELL28.java:8 )
at sun.reflect.Nat iveMethodAccess orImpl.invoke0( Native Method)
at sun.reflect.Nat iveMethodAccess orImpl.invoke(N ativeMethodAcce ssorImpl.java:3 9)
at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java:25)
at java.lang.refle ct.Method.invok e(Method.java:5 85)
at bluej.runtime.E xecServer$3.run (ExecServer.jav a:858)

[/error]
Sep 17 '07 #1
2 5913
FishVal
2,653 Recognized Expert Specialist
Hi, there.

To the best of my knowledge VALUES list should be delimited with commas, not pluses.
Sep 17 '07 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
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,Phonen o,Dateofbirth,C ompla int)VALUES(" + no + ", '" + f_name + "', '" + l_name + "', " + phone + ", #" + b_day + "#, '" + text + "')";
Sep 18 '07 #3

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

Similar topics

3
3717
by: CSDunn | last post by:
Hello, I have a situation with MS Access 2000 in which I need to display report data in spreadsheet orientation (much like a datasheet view for a form). If you think of the report in terms of what a spreadsheet might show, the column names will actually be dynamic, based on data from a SQL Server 2000 database. The row data will also come from the same database. So in this case, I will have a main report and a subreport. I've already tried...
2
8679
by: Robert McEuen | last post by:
Using Access 97, Windows XP I'm receiving a Numeric Field Overflow error during text import that I did not receive before I split my database. Another thread I found suggested that the cause of this error might be due to columns on the text file being in a different order than fields in the destination table, but they're the same in my case. I'm thinking a workaround might be to import to a temp table in the front-end, run an append...
2
8148
by: ralamo | last post by:
When i execute the following insert query, the above mentioned error is coming. Anything wrong in the query? INSERT INTO ECN_1 (Old_SbPartNo, Old_PartDesc, Old_ManPartNo, Old_Manuf, Old_Vendor, Old_RefDesi, Old_Qty, New_SbPartNo, New_PartDesc, New_ManPartNo,New_Manuf, New_Vendor, New_RefDesi, New_Qty) select * from (select SB0014.SbPartNo, SB0014.partDesc, SB0014.mANpARTnO, SB0014.manufacturer,
3
6903
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records from rsSource into rsDest - if it finds a key violation then it deletes the current record from rsDest and adds the new record from rsSource. This works perfectly - but only for the first found duplicate record, it brings up the error
3
2750
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command that I can use instead? Cheers Nicolaas
9
3373
by: Kosmos | last post by:
I'm getting this error message: Number of query values and destination fields are not the same. This is the code: INSERT INTO tblDateDifference ( DateDifference ) SELECT tblContracts.EndDate As EndDate, IIf( > EndDate, DaysToCompletion(EndDate), DaysCompleted(EndDate)) AS DateDifference, FROM tblContracts; Can someone please tell me why I'm getting this error message? PLEASE?!?! lol
9
9717
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a master-child link to the first subform. subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK Child Field: TrainingModuleTopicSK
6
3477
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am using MS-Access 2000 database table for this app. Note that the datatype of all the fields mentioned above are Text. Apart from the above columns, there's another column in the DB table named 'RegDateTime' whose datatype is Date/Time which is...
3
1364
by: Shokoth | last post by:
Hi I have been trying to run this code, and what it is doing is inserting records into a table called tblRequestByService. the values that it is inserting are taken from the form itslef (They are normal text boxes). every time i click the button to do that, i get the folling error message: "Number Of Query Values and Destination Fields are not the same". I have been having similar problems throughout. i know that the number of fields that i...
0
9543
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10029
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.