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)

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.