I have a database column with 54 values.I want to create a table for each values.But my code only creates first value table then it shows an error due to closing ResultSet.
How can I reopen the ResultSet using a loop? I need all 54 valued tables.
Code:
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);
}
}
It shows following error
java.sql.SQLException: Operation not allowed after ResultSet closed