Servlet SQL INSERT error

Hi,

I have the following error when trying to insert ino an oracle database. The server Im using is TomCat.

SQLException: ORA-00917: missing comma

This is my code:

public boolean registeruser(String Fname, String Lname, String Email, String Username, String Password, int Mark1, int Mark2, int Mark3, int Average, double Session) throws IOException, SQLException, ClassNotFoundException{

Connection conn;

String theVerifiedRegistration = "insert into students VALUES('"+Fname+"', '"+Lname+"', '"+Email+"', '"+Username+"', '"+Password+"', '"+Mark1+"', '"+Mark2+"', '"+Mark3+"', '"+Average+"', '"+Session+"')";

Class.forName("oracle.jdbc.driver.OracleDriver");

conn = DriverManager.getConnection("jdbc:oracle:thin:@studsol01:1521:studb2","moleary","technet");

Statement stmt;

stmt = conn.createStatement();

ResultSet rset;

rset = stmt.executeQuery(theVerifiedRegistration);

rset.next();

String theUsername = rset.getString(1);

conn.close();

I presume the critical line is :

String theVerifiedRegistration = "insert into students VALUES('"+Fname+"', '"+Lname+"', '"+Email+"', '"+Username+"', '"+Password+"', '"+Mark1+"', '"+Mark2+"', '"+Mark3+"', '"+Average+"', '"+Session+"')";

Any assistance would be appreciated.

[1367 byte] By [moleary77a] at [2007-9-20]
# 1

> I presume the critical line is :

> String theVerifiedRegistration = "insert into students

> VALUES('"+Fname+"', '"+Lname+"', '"+Email+"',

> '"+Username+"', '"+Password+"', '"+Mark1+"',

> '"+Mark2+"', '"+Mark3+"', '"+Average+"',

> '"+Session+"')";

Close. The critical piece of information is the value of that string. What is it?

DrClapa at 2007-7-12 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

I figured this out.

Its because I entered an apostrophe ' in the form field being submitted.

The code cant handle this in the INSERT statement because it treats it as one of the apostrophes' surrounding the field to be inserted.

Works fine if you leave out the '.

Now all I have to do is change my name from O'Leary to OLeary.

moleary77a at 2007-7-12 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Also Works if you double up the apostrophe.

I created a small piece of Java code to enter an extra ' in a string if a single ' is encountered.

When I enter O'Leary in the form, this code changes it to O''Leary before performing the SQL insert.

SQL then recognises this as O'Leary and inserts it into the table.

moleary77a at 2007-7-12 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...