Results 1 to 4 of 4
- 10-23-2009, 01:25 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 31
- Rep Power
- 0
cant find the error in the following SQL statemen but it just wont work!!
I have the following codein my project.My IDE(netbeans) points out an error in the
statement which I cant spot.Anyone willing to proof read and point out the error?Java Code:executeUpdate
Java Code://All unseen variablesdeclaration and constructors were declared above^^^ public void registerNewStudent() { String fname=newStudent.getFirstName(); String lname = newStudent.getLastName(); String regNumber = newStudent.getKURegNumber(); String campus = newStudent.getCampus(); String nationalID = newStudent.getNational_ID(); String courseCode, studentID, yearOfEntry; String str = regNumber; String split []; split = str.split("/"); courseCode = split[0]; studentID = split[1]; yearOfEntry = split[2]; Connection con = null; try { Class.forName(DRIVER).newInstance(); Properties p = new Properties(); p.put("user", "root"); p.put("password", "mysecret"); con = DriverManager.getConnection(DATABASE_URL,p); Statement stmt = con.createStatement(); stmt.executeUpdate("INSERT into kustudents (StudentID, FirstName, // ^^^^^^^everything in the project is fine until here ^^^^:confused: LastName, CourseCode, YearOfEntry, RegNumber, National_ID, Campus) " + "VALUES ("+studentID+",'"+fname+"','"+lname+"','"+courseCode+"','"+yearOfEntry+"','" +regNumber+"','" +nationalID+"','"+campus+"')"); //I have a feeling I messed up with the above. stmt.close(); System.out.print("Thank you for registering.."); } //all the rest proceeds:p
- 10-23-2009, 01:29 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Don't create queries by concatenating strings like that.
Use a PreparedStatement instead.
- 10-23-2009, 01:40 PM #3
Like what ro35198x said ,u have to use PreparedStatement for this things.
Another suggestion,u should not directly give big query statement for execution.debugging will be a problem.Use StringBuffer for framing query and then use toString() method for stringbuffer object and use it in executeupdate().Before passing just put s.o.p for seeing ur query and u can easily correct if something goes wrong.Ramya:cool:
- 10-26-2009, 11:42 AM #4
Member
- Join Date
- Oct 2009
- Posts
- 31
- Rep Power
- 0
Similar Threads
-
error cannot find symbol
By jcoon3 in forum New To JavaReplies: 3Last Post: 09-27-2009, 10:56 PM -
'Cannot find symbol' error
By minihazard10 in forum New To JavaReplies: 6Last Post: 10-10-2008, 04:05 AM -
save will work but load wont?!?!
By Sticks_ll in forum New To JavaReplies: 1Last Post: 06-12-2008, 04:19 AM -
Error: cannot find symbol
By silvia in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:39 AM -
Error: cannot find symbol
By cachi in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks