我有一个包含 54 个值的数据库列。我想为每个值创建一个表。但是我的代码只创建第一个值表,然后由于关闭而显示错误ResultSet
。
如何重新打开ResultSet
使用循环?我需要所有 54 个有价值的表。
代码:
public void createTableStudent() {
try {
connection = (Connection) dbSource.getConnection();
String qry = "SELECT studentName From batcha ";
System.out.println(qry);
stmt = (PreparedStatement) connection.prepareStatement(qry);
rs = stmt.executeQuery();
while (rs.next()) {
String check=new String(rs.getString(("studentName")));
String student = check.replaceAll("\\s","");
Class.forName("com.mysql.jdbc.Driver");
connection = (Connection) DriverManager.getConnection(DB_URL_table, USER, PASS);
String sql1 = "CREATE TABLE IF NOT EXISTS "+student+" " +
"(id INTEGER not NULL AUTO_INCREMENT, " +
" fcltyName VARCHAR(255), " +
"CommunicationOral INTEGER, "+
"Communicationwritten INTEGER, "+
"Leadership INTEGER, "+
"AnalyticalAbilities INTEGER, "+
"Interpersonalskills INTEGER, "+
"DecisionMakingSkills INTEGER, "+
"SelfConfidence INTEGER, "+
"Creativity INTEGER, "+
"Punctualityregularity INTEGER, "+
"GeneralAwareness INTEGER, "+
"Commitment INTEGER, "+
"Hardwork INTEGER, "+
" PRIMARY KEY ( id ))";
stmt.executeUpdate(sql1);
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(AdminHome.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(AdminHome.class.getName()).log(Level.SEVERE, null, ex);
}
}
它显示以下错误
java.sql.SQLException: Operation not allowed after ResultSet closed