I have tried the below code to store all the data of array list(table).But doesn't give any error or the required output.
public class Dbops {
String url = "jdbc:mysql://localhost:3306/ITStuffDB";
String username = "root";
String password = "";
ResultSet rs = null;
public boolean addData(ArrayList<ArrayList<String>> table){
try {
System.out.println(table.size());
for (int i = 0; i < table.size(); i++) {
Connection con1 = (Connection) DriverManager.getConnection(url, username, password);
String query = "INSERT INTO Data (Col1,Col2,Col3) VALUES (?,?,?)";
PreparedStatement pst1 = (PreparedStatement) con1.prepareStatement(query);
pst1.setString(1, table.get(i).get(0));
pst1.setString(2, table.get(i).get(1));
pst1.setString(3, table.get(i).get(2));
pst1.executeUpdate();
pst1.close();
con1.close();
}return true;
} catch (Exception e) {
return false;
}
}
}
How can i handle this correctly?