Hi. I am developing an application program in java. I use MsAccess for keeping data.
I had a problem with sql insert method. -
-
public void AddPatient()
-
{
-
String no= numberinput.getText();
-
String f_name=nameinput.getText();
-
String l_name= surnameinput.getText();
-
String phone =phoneinput.getText();
-
String b_day=dateofbirthinput.getText();
-
String text=textpane.getText();
-
-
-
try{
-
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
-
con= DriverManager.getConnection(url);
-
st= con.createStatement();
-
sql="INSERT INTO PatientDB (PatientID,Name,Surname,Phoneno,Dateofbirth,Complaint)VALUES(no+f_name+ l_name +phone + b_day+ text)";
-
-
st.executeUpdate(sql);
-
con.close();
-
}
-
-
catch(ClassNotFoundException e)
-
{}
-
-
-
catch(SQLException ex)
-
{
-
ex.printStackTrace();
-
}
-
-
}
-
-
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]
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.
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 + "')";
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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,
|
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
|
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
| |
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
|
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
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |