954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MS Access database problem

i have created program below ,but it does not run successfully why

import java.sql.*;


public class Bank {

   
    public static void main(String[] args) throws Exception {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        // TODO code application logic here
   try{
       Connection cn=DriverManager.getConnection("jdbc:odbc:rushiDSN");
       System.out.println("Connected Successfully");
       Statement stmt=cn.createStatement();
       stmt.executeUpdate("CREATE TABLE Author(AuID Number(3), AuName Char(15), AuAddr Char(30))");
       System.out.println("Table created successfully");
       stmt.close();
       cn.close();
   }catch(Exception e){System.out.println(e.getMessage());}
    }
}


it shows following error
error:
Connected Successfully
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in CREATE TABLE statement.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3109)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:337)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:287)
at Bank.main(Bank.java:16)

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

i have created program below ,but it does not run successfully why

import java.sql.*;


public class Bank {

   
    public static void main(String[] args) throws Exception {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        // TODO code application logic here
   try{
       Connection cn=DriverManager.getConnection("jdbc:odbc:rushiDSN");
       System.out.println("Connected Successfully");
       Statement stmt=cn.createStatement();
       stmt.executeUpdate("CREATE TABLE Author(AuID Number(3), AuName Char(15), AuAddr Char(30))");
       System.out.println("Table created successfully");
       stmt.close();
       cn.close();
   }catch(Exception e){System.out.println(e.getMessage());}
    }
}

it shows following error error: Connected Successfully java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in CREATE TABLE statement. at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956) at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113) at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3109) at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:337) at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:287) at Bank.main(Bank.java:16)


well there is definitely a syntax error in your SQL statement, though i cant see it: http://www.w3schools.com/sql/sql_create_table.asp make sure there is a space between "CREATE TABLE Author ()".

[edit] i think i found the main problem, there is no data type as "Number" in sql: http://www.w3schools.com/sql/sql_datatypes.asp

DavidKroukamp
Practically a Master Poster
Team Colleague
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
 

Yes, you are right, there is no data type as "Number" in sql.
Thanks for help problem has solved.

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You