我有这个代码,我希望将我的表ArrayList
存储在我的database
public class globaleCollab {
public static void main(String[] args) throws ClassNotFoundException {
long startTime = System.currentTimeMillis();
System.out.println(" les rating : ");
String idoperateur = "00000006092";//operateur cible njibh m session
sort1 sor = new sort1();
ArrayList<Integer> table = sor.tri();
String resultat_final = null;
for (int i = 0; i < table.size(); i++) {
resultat_final = resultat_final + "," + table.get(i).toString();
}
System.out.println(table);
System.out.println("-------" + resultat_final);
//insrt id user, resultat_final, temps d'exe, k ,
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
System.out.println("l temps est " + elapsedTime + "ms");
Connection con = null;
PreparedStatement ps;
ResultSet rs;
String query;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bd_recommandation", "root", "");
query = "insert into statistic (idoperateur,id) values(?,?)";
ps = con.prepareStatement(query);
ps.setString(1, idoperateur);
ps.setString(2, resultat_final);
//ps.setInt(3, k);
//ps.setLong(4, elapsedTime);
// ps.setString(2, resultat_final);
System.out.println("000000000000000000000000000");
ps.executeUpdate();
} catch (Exception e) {
}
}
但它无效
答案 0 :(得分:0)
首先:捕获异常,检查sql错误或数据错误 第二:ps.setString()方法索引从0
答案 1 :(得分:0)
如果您事先知道数组的最大大小,请参阅:this page of the JDBC documentation。但是,如果数组的大小未知,我建议创建一个新表,其中每一行都是一个索引,并且有一列保存整数。