473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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 1989
Dököll
2,364 Expert 2GB
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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...
0
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
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,...

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.