如何使用java向sqlite添加新列
如何在Java中向Sqlite表添加新列并保留数据。我在Android中见过并使用过onUpgrade方法,但在“原生java”中没有发现类似的方法 我的数据库是一个以前加载了整个表结构的文件,我通过这种方式连接到它:如何使用java向sqlite添加新列,java,sqlite,Java,Sqlite,如何在Java中向Sqlite表添加新列并保留数据。我在Android中见过并使用过onUpgrade方法,但在“原生java”中没有发现类似的方法 我的数据库是一个以前加载了整个表结构的文件,我通过这种方式连接到它: public static Connection sqliteInit() { Connection cnx = null; String bd= System.getProperty("user.home")+File.s
public static Connection sqliteInit() {
Connection cnx = null;
String bd= System.getProperty("user.home")+File.separator +".local"+File.separator+"assets"+File.separator+"app_database.db";
String url = "jdbc:sqlite:"+bd;
try {Class.forName("org.sqlite.JDBC");
cnx = DriverManager.getConnection(url);
} catch (SQLException | ClassNotFoundException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return cnx;
}
请阅读以下内容:
Statement stmt = cnx.createStatement();
stmt.executeUpdate("alter table ...");