PreparedStatement操作sqllite数据库批量提交报java.sql.SQLException: NYI错误
代码如下:
程序代码:public static void main(String[] args) throws SQLException {
Connection con = null;
TimeSpan ts = new TimeSpan();
ts.SetStartTime();
try
{
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:"+filename);
con.setAutoCommit(false);
//Statement stm = con.createStatement();
PreparedStatement prep = con.prepareStatement("insert into book (Name,author,Price) values(?,?,?);");
for(int i=1;i<10001;i++)
{
prep.setString(1, "BookName"+i);
prep.setString(2, "Writer"+i);
prep.setInt(3, i);
prep.addBatch();
}
//prep.executeUpdate();
//con.setAutoCommit(false);
prep.executeBatch();
();
con.setAutoCommit(true);
/*
prep.setString(1, "水浒传");
prep.setString(2, "施耐庵");
prep.setInt(3, 89);
*/
ts.SetEndTime();
ts.GetSpanTime();
/* con.setAutoCommit(true);
Statement stm = con.createStatement();
ResultSet rs = stm.executeQuery("select * from book");
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4));
}
*/
}
catch(Exception e)
{
try
{
con.rollback();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
System.out.println(e.getMessage());
System.out.println(e.toString());
}
finally
{
try
{
con.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
单次提交executeUpdate()没有任何问题,批量提交executeBatch()总是抛异常









