Results 1 to 4 of 4
  1. #1
    KyleS is offline Member
    Join Date
    Feb 2012
    Location
    Albany New York
    Posts
    4
    Rep Power
    0

    Default SQL error in Java

    I am having trouble with a method to check the database tables or if needed construct tables

    Java 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;
    Here is the output,
    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

    Java Code:
    stmt.executeUpdate("create table someTable" +
    					"(key varchar(20), firstField varchar(20), " +
    					"secondField varchar(500), lastField varchar(max)");
    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.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: SQL error in Java

    Print out that SQL.
    You're missing a bracket (assuming the syntax in general is correct).
    Please do not ask for code as refusal often offends.

  3. #3
    KyleS is offline Member
    Join Date
    Feb 2012
    Location
    Albany New York
    Posts
    4
    Rep Power
    0

    Default Re: SQL error in Java

    Tolls thank you for your reply I did as you said and added a bracket

    here is the SQL Statement:

    Java Code:
    create table someTable(key varchar(20), someField varchar(20), someOtherField varchar(500), yetAnotherField varchar(max))

    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:153)
    at languageInterperater.databaseConnector.connect(dat abaseConnector.java:54)
    at languageInterperater.langInterpMain.starting(langI nterpMain.java:66)
    at languageInterperater.langInterpMain.main(langInter pMain.java:18)
    Problem constructing database or with SQL Query
    Query is create table someTable(key varchar(20), someField varchar(20), someOtherField varchar(500), yetAnotherField varchar(max))
    Thanks again!
    Last edited by KyleS; 03-09-2012 at 07:11 PM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: SQL error in Java

    You'll have to read the Access docs and find out what the syntax for their create tables is.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Replies: 16
    Last Post: 01-11-2012, 02:45 PM
  2. Replies: 0
    Last Post: 01-21-2011, 12:43 PM
  3. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  4. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  5. Replies: 1
    Last Post: 10-26-2009, 04:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •