insert Jtable Data into Database.
int rows = jTable1.getRowCount();
System.out.println(""+rows);
for(int row = 0; row<rows ; row++)
{
String name = (String) jTable1.getValueAt(row, 0);
String mail = (String) jTable1.getValueAt(row, 1);
String add = (String) jTable1.getValueAt(row, 2);
String pass = (String) jTable1.getValueAt(row, 3);
try{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/naveen","root","root");
String query = "insert into jtable(name,mail,address,password) values(?,?,?,?)" ;
PreparedStatement stmt = con.prepareStatement(query);
stmt.setString(1, name); //Invoice No
stmt.setString(2, mail); //Code
stmt.setString(3, add); //Description
stmt.setString(4,pass); //Bonusable
stmt.addBatch();
stmt.executeBatch();
con.commit();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "Cannot save. "+ ex);
}
}
set();