如何使用java在mySql的表列中存储数组值

你好,我试图在两个结果集中检索数据.然后我将结果集存储到String Array中,在此过程之后我必须将我的String数组存储到另一个表中,如何这样告诉我..try {Class.forName(com.mysql.jdbc.Driver);Connection con = (Co...

你好,我试图在两个结果集中检索数据.然后我将结果集存储到String Array中,在此过程之后我必须将我的String数组存储到另一个表中,如何这样告诉我..

try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = (Connection) DriverManager.
         getConnection("jdbc:mysql://localhost:3306/lportal", "root", "ubuntu123");
    PreparedStatement stmt = (PreparedStatement) con.
         prepareStatement("SELECT * FROM  Testi_Testimonial where subject = ?");
    stmt.setString(1, search);
    stmt.execute();
    rs = (ResultSet) stmt.getResultSet();
    while (rs.next()) {
      anArray[i] = rs.getString("subject");
      System.out.println(anArray[i]);
      i++;
      count++;
    }
    PreparedStatement stmt1 = (PreparedStatement) con.
         prepareStatement("SELECT * FROM Testi_Testimonial where subject != ?");
    stmt1.setString(1, search);
    stmt1.execute();
    rs1 = (ResultSet) stmt1.getResultSet();
    while (rs1.next()) {
      anArray[i] = rs1.getString("subject");
      System.out.println(anArray[i]);
      i++;
      count++;
    }
} catch (Exception e) {
  e.printStackTrace();
  System.out.println("problem in connection");
}

请告诉我如何将我的数组存储到Temp表?我的“Temp”表有列主题我想将myArray存储到主题栏…请告诉我该怎么做.

解决方法:

在rs中获取结果集后尝试这个:

   PreparedStatement st = (PreparedStatement) con.prepareStatement("insert into temp values(?)");
    i=0;
   while(rs.next())
    {
      st.setString(1,anArray[i]);
      st.executeUpdate();
      i++;
    }

本文标题为:如何使用java在mySql的表列中存储数组值

基础教程推荐