1、如果是执行插入更新等不需要返回ResultSet的,可参照下面:
/**执行插入和更改操作,无返回ResultSet
public static void updateUser() throws Exception {
String rs = SqliteDB.GetHtttpLink(“http://127.0.0.1:18181/db/upuser”);
JSONArray array = JSONArray.parseArray(rs);
for (int i = 0; i < array.size(); i++) {
JSONObject obj = array.getJSONObject(i);
int id = Integer.parseInt(obj.getString(“id”));
String sql = “insert into user values(?,?,?,?,?,?,?,?)”;
Connection con = SqliteDB.getCon();
PreparedStatement pst = con.prepareStatement(sql);
pst.setInt(1, id);
pst.set…….. (其他省略.)
pst.addBatch();//最主要是就是这2行
pst.executeBatch();//执行
}
}
2、/**执行查询操作
public static void selectUser() throws SQLException {
Connection connection = SqliteDB.getCon();
PreparedStatement pst = connection.prepareStatement(“select comment from user;”);
ResultSet resultSet = pst.executeQuery();//后面这个不能带sql
while (resultSet.next()) {
String s = resultSet.getString(“comment”);
logger.info(“———” + s);
}
}