private static void creatTable(){
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e) {
System.out.println(e.getMessage());
}
try{
Connection con=DriverManager.getConnection("jdbc:odbc:dypSystem");
Statement stmt=con.createStatement();
String sql="creat table custom(authid INT,name Char(10),phone INT,bir Char(15),ins Char(20),insNum int)";
    stmt.executeUpdate(sql);
    sql="insert into custom(authid,name) values(001,'hgj')";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}
catch(SQLException e) {
System.out.println(e.getMessage());
}

}
为什么这段代码会出现异常?
[Microsoft][ODBC Microsoft Access Driver] 无效的 SQL语句;期待 'DELETE'、'INSERT'、'PROCEDURE'、'SELECT'、或 'UPDATE'。

解决方案 »

  1.   

    creat table custom(authid INT,name Char(10),phone INT,bir Char(15),ins Char(20),insNum int)这个写错了应该写成为
    create table custom(authid int,names Char(10),phone INT,bir Char(15),ins Char(20),insNum int) 你的creat少写个e,还有name是sql里面的关键字,换成其他的。