I am having trouble with a method to check the database tables or if needed construct tables
Here is the output,Code:protected void checkTable() //TODO change to private
{
System.out.println("Checking database configuration ");
try
{
DatabaseMetaData dbm = con.getMetaData();
ResultSet rs = dbm.getTables(null, null, "TABLENAME", null);
if (rs.next())
{
System.out.println("Database configuration check: passed");
}
else
{
System.out.println("Database configuration check: failed");
System.out.println("Creating tables: ");
stmt = con.createStatement();
stmt.executeUpdate("create table someTable" +
"(key varchar(20), firstField varchar(20), " +
"secondField varchar(500), lastField varchar(max)");
}
}
catch(SQLException problem)
{
problem.printStackTrace();
System.out.println("Problem constructing database");
System.exit(0);
}
}
private Connection con;
private Statement stmt;
Quote:
Checking database configuration
Database configuration check: failed
Creating tables:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in field definition.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unkn own Source)
at languageInterperater.databaseConnector.checkTable( databaseConnector.java:151)
at languageInterperater.databaseConnector.connect(dat abaseConnector.java:51)
at languageInterperater.langInterpMain.starting(langI nterpMain.java:66)
at languageInterperater.langInterpMain.main(langInter pMain.java:18)
Problem constructing database
I think it is in the SQL statement in this line of Java code
Can someone check my code? It is probably a blatant error but since I am a bit of a SQL noob I am missing it thanks so much for your help.Code:
stmt.executeUpdate("create table someTable" +
"(key varchar(20), firstField varchar(20), " +
"secondField varchar(500), lastField varchar(max)");
