[RESOLVED] Java - SQL Exception - Create table syntax error
Hi everybody,
I had a clean compile with an SQL Exception from a possible syntax error, but I can't figure out what I'm doing wrong. See the Error msg below:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in CREATE TABLE statement.
Thanks.
Code:
import java.lang.*;
import java.lang.String;
import java.awt.*;
import java.sql.*;
// @author GIXTIAN
public class NewConn
{
public static void main(String[]args)
{
try
{ //Specify Driver to be used as a connection bridge
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Establish connecton to the database (in this case "TPersonsDatabase.mdb"
Connection conn = DriverManager.getConnection(
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:/TPersonsDatabase.mdb"
);
//Create Sql statement using the "statement function":
Statement stmt = conn.createStatement();
stmt.executeUpdate("CREATE TABLE TPERSONS" +
"FIRSTNAME VARCHAR(20), LASTNAME VARCHAR(20), SSN VARCHAR(9)" +
"SALARY INTEGER");
stmt.executeUpdate("INSERT INTO TPERSONS VALUES('GIFT', 'XTIAN', '148942851' 9000");
stmt.executeUpdate("INSERT INTO TPERSONS VALUES('PROF.', 'DEVI', '199952584', 10000");
stmt.executeUpdate("INSERT INTO TPERSONS VALUES('JASPER', 'CHUCK', '879458974', 5000");
stmt.executeUpdate("INSERT INTO TPERSONS VALUES('NOBLE', 'JACKSON', 145854477', 11000");
stmt.executeQuery("SELECT * FROM TPERSONS");
}
catch(ClassNotFoundException ex)
{
System.out.println(ex.toString());
}
catch(SQLException ex)
{
System.out.println(ex.toString());
}
}
}
Gift
Re: Java - SQL Exception - Create table syntax error
Think about what that string will look like when it is concatenated:
"CREATE TABLE TPERSONSFIRSTNAME VARCHAR(20), LASTNAME VARCHAR(20), SSN VARCHAR(9)SALARY INTEGER"
That doesn't look quite right to me. ;)
Re: Java - SQL Exception - Create table syntax error
Good morning "Si". I didn't realize I was missing "(" in the query.
It's working now.
Thanks.
Gift.