我在创建过程时CREATE TABLE语句中的语法错误

时间:2014-01-02 16:08:35

标签: java ms-access jdbc odbc

我有一个非常奇怪的问题。我刚刚编写了一个应该创建过程然后执行它的代码。但它给了我这个错误:

  Exception in thread "main" java.sql.SQLException: [Microsoft][Driver ODBC Microsoft Access] Syntax error in statement CREATE TABLE 
        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 mDat.procedures.createProcedure(procedures.java:25)
    at mDat.procedures.main(procedures.java:14)

这是我的代码:

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class procedures { 
    static Connection con;
    static String procedure;
    public static void main(String[]args) throws ClassNotFoundException, SQLException{
        getConnection("jdbc:odbc:TestDatabaze");
        createProcedure();
        executeProcedure();
        con.close();
    }
    static void getConnection(String connection) throws ClassNotFoundException, SQLException{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con=DriverManager.getConnection(connection);
    }
    public static void createProcedure() throws SQLException{
        procedure="CREATE PROCEDURE newest_user AS SELECT Firstname, Lastname FROM members WHERE ID= max(ID)";
        Statement s = con.createStatement();
        s.execute(procedure);
        s.close();
    }
    public static void executeProcedure() throws SQLException{
        CallableStatement cs=con.prepareCall("{CALL newest_user}");
        String fn=cs.getString(1);
        String ln=cs.getString(2);
        System.out.println("Name of the newest user in database is "+fn+" "+ln);
    }
}

我真的不知道为什么它会给我这个错误,因为没有创建表的代码。谢谢您的帮助。

0 个答案:

没有答案