我正在尝试将数据插入到sqlite表中但是它给了我异常没有这样的异常。请检查我的代码并告诉我应该做出哪些更改?
static Connection con;
public static Connection getConnection()
{
try
{
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:/home/zack/another.db");
con.setAutoCommit(false);
System.out.println("Opened database successfully");
}
catch(Exception e)
{
System.out.println("EXCEPTION IN :: SqliteCon:"+e.getMessage());
}
return con;
}
这是我的插入命令文件。
public String execute()
{
BufferedReader br;
try {
Connection con = SqliteCon.getConnection();
Statement stmt = con.createStatement();
br = new BufferedReader(new FileReader(
"/home/Zack/Desktop/session.csv"));
String line;
while ((line = br.readLine()) != null) {
String[] value = line.split(","); // your seperator
stmt.executeUpdate("INSERT into sessionTab values('jack','pass','NYC'")
//later i will insert values from CSV file
br.close();
}
}
catch (Exception e) {
System.out.println("Exception in UploadData class");
e.printStackTrace();
}
return SUCCESS;
}
我还将jar文件添加到我项目的WEB-INF / lib /中
答案 0 :(得分:0)
终于解决了这个问题!!!从sqliteman切换到Firefox sqlite插件,并将db文件的扩展名从.db更改为.sqlite。