尝试在sqlight中创建表时,请继续获取exceptionKeep

时间:2018-01-29 12:56:38

标签: java sqlite

我正在尝试在sqlight中创建一个表。我使用以下代码          //这将通过一个例外,因为该表已经存在

  sql = "CREATE TABLE IF NOT EXISTS exchangesd (\n"
                    + " id integer PRIMARY KEY,\n"
                    + " name text ,\n"
                    + " publickey ,\n"
                    + " privetkey L,\n"
                    + " phrase ,\n"
                    + ");";
         stmt.execute(sql);

行stmt.execute(sql);使用消息

生成异常
"org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)"

代码:

void test()
 {

     ted++;
     try {

         Connection c = null;
         Class.forName("org.sqlite.JDBC");
         c = DriverManager.getConnection("jdbc:sqlite:ted.db");

         Statement stmt = null;

         stmt = c.createStatement();
         String sql;

         // this will now through a exception becouse the table allready exist
         sql = "CREATE TABLE IF NOT EXISTS exchangesd (\n"
                    + " id integer PRIMARY KEY,\n"
                    + " name text ,\n"
                    + " publickey ,\n"
                    + " privetkey L,\n"
                    + " phrase ,\n"
                    + ");";
         stmt.execute(sql);  // EXCEPTION GOES OF HEAR

         sql = "INSERT INTO exchangesd (name, publickey, privetkey, phrase ) " +
                 "VALUES ('exchangea', publickkeya, 'privet keya', 'phasea' );"; 
         stmt.executeUpdate(sql);



     }catch(Exception e)
     {
         ted++;
     }
}   

1 个答案:

答案 0 :(得分:1)

您在这里有额外的,

+ " phrase ,\n"
+ ");";

并且在语法上不可能看到以下)时,SQL解析器失败。