Java 使用SQLite创建表失败
我的项目是JavaSwing,它需要一个表,所以我尝试使用SQLite。 当我使用SQLite时,它可以创建一个连接,但当创建表时它失败了。请教我,提前谢谢Java 使用SQLite创建表失败,java,database,sqlite,Java,Database,Sqlite,我的项目是JavaSwing,它需要一个表,所以我尝试使用SQLite。 当我使用SQLite时,它可以创建一个连接,但当创建表时它失败了。请教我,提前谢谢 public class SqliteMethod { private Connection conn; private static String Create_Table = "create table if not exists table_message(" + "_id integer primary key a
public class SqliteMethod {
private Connection conn;
private static String Create_Table = "create table if not exists table_message("
+ "_id integer primary key autoincrement,"
+ "name varchar(50),"
+ "input_id varchar(50),"
+ "picture blob,"
+ "template blob"
+ ")";
public SqliteMethod() {
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:scanner.db");
Statement stat = conn.createStatement();
if (!stat.execute(Create_Table))
System.out.println("create table failed");
stat.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
conn
不是null
,但当它转到创建表时失败
if (!stat.execute(Create_Table))
System.out.println("create table failed");
报告说:
返回:true
如果第一个结果是ResultSet
对象<代码>错误如果是更新计数或没有结果
此语句不是SELECT查询,因此不返回任何数据,因此不存在错误。(错误将导致出现
SQLException
)这与Swing无关,“请教我”因此不是一项辅导服务。您忘记了stat.executeUpdate(创建表);我记得,Sqlite没有varchar,而是有文本。