473,473 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Having a syntax error in INSERT statement on the date and time

1 New Member
These are the codes. I cant see any error there. Please kindly help. Thanks.

void saveMedicalRecords() {
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(url2, username, password);
Statement statement = connection.createStatement();
sql = "INSERT INTO medicalrecords (NRIC, Time, Diagnosis, MC, NoOfDays, Prescription1, Qty1, Prescription2, Qty2, Prescription3, Qty3, Prescription4, Qty4, Prescription5, Qty5, Additional) VALUES ('"+txtPID3.getText()+"',"+timeNow+",'"+txtDiagnos is.getText()+"',"+MC_String+",'"+txtDays.getText() +"','"+txtDrug1.getText()+"',"+txtQ1.getText()+",' "+txtDrug2.getText()+"',"+txtQ2.getText()+",'"+txt Drug3.getText()+"',"+txtQ3.getText()+",'"+txtDrug4 .getText()+"',"+txtQ4.getText()+",'"+txtDrug5.getT ext()+"',"+txtQ5.getText()+",'"+txtAdd.getText()+" ')";
System.out.println("sql is : "+sql);
statement.executeUpdate(sql);
connection.close();
}
catch (Exception ex){
ex.printStackTrace();
}
saySavedMedicalRecords();
}
Nov 11 '09 #1
1 1991
Dököll
2,364 Recognized Expert Top Contributor
Can you tell us a little more? Where are the errors... Please post a bit of it and a brief explaination. I suspect you are not formatting the date variable upon inserting. What is the date format in the db.

I would also use preparedStatement to fend off having to format dates going in. Also preparedStatement is of great use against SQL injection.

http://www.java2s.com/Code/Java/Database-SQL-JDBC/DemoPreparedStatementSetBytes.htm


In a bit!
Nov 18 '09 #2

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

Similar topics

3
by: Mohammed Mazid | last post by:
Can anyone please help me here? Basically I have modified the source code and understood it but when I update a record in the db using a JSP, it gives me an error "The flight you selected does...
7
by: wireless200 | last post by:
How can I cause my insert statement to skip over (without failing) rows where there's a primary key constraint violation? I've got a case where daily I insert >500k rows of daily data, where the...
2
by: Alicia | last post by:
Does anyone know why I am getting a "Syntax error in Create Table statement". I am using Microsoft Access SQL View to enter it. Any other problems I may run into? CREATE TABLE weeks (...
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
5
by: Saber | last post by:
I'm using a table named myTable in Access, but when I try it I get: Syntax error in INSERT INTO statement. in access db, the Cat1,Cat2,..,Cat5 are Yes/No and their format is True/False any idea?...
5
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details:...
1
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. ...
1
by: balleyman47 | last post by:
getting the following error when executing an insert statement: java.lang.IllegalArgumentException: Date/Time must be JDBC format running on UDB 8.2 fix pack 10 using IBM type IV driver. Query...
3
by: DontB3 | last post by:
Hi, I'm new in this forum, and i hope someone can help. I'm creating an automatic application that transfer a database from Access -> DBF -> Oracle. When My App try to execute Insert SQL...
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
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,...
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...
1
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
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.