Problem with JTable and MySQL
I have a problem when updating MySQL database with values from JTable
when i run this code
Code :
package rd;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.swing.*;
/**
*
* @author Daniel Miovski
*/
public class ticketsql {
private void saveCustomers() {
Connection conn = javaconnect.createConnection();
PreparedStatement pstm = null;
int index = 1;
int count = bettingform.TabCombination.getRowCount();
try {
for (int i = 0; i < count; i++) {
Object tip = GetData(bettingform.TabCombination, i, 1);
Object quote = GetData(bettingform.TabCombination, i, 2);
Object stake = GetData(bettingform.TabCombination, i, 3);
String value1 = bettingform.TFTSerial.getText();
System.out.println(value1);
String value2 = tip.toString();
System.out.println(value2);
double value3 = Double.parseDouble(quote.toString());
System.out.println(value3);
double value4 = Double.parseDouble(stake.toString());
System.out.println(value4);
String value5 = bettingform.tfjpcode.getText();
System.out.println(value5);
String sql = "insert into probatiket (TicketId, Game, Quote, PayIn, JP2Code) values (?, ?, ?, ?, ?)";
System.out.println("Preperation");
pstm = conn.prepareStatement(sql);
pstm.setString(1, value1);
pstm.setString(2, value2);
pstm.setDouble(3, value3);
pstm.setDouble(4, value4);
pstm.setString(5, value5);
index++;
}
System.out.println("execute");
pstm.executeUpdate();
System.out.println("saved Successfully");
} catch (Exception e) {
System.out.println(e);
}
}
public Object GetData(JTable table, int row_index, int col_index) {
return bettingform.TabCombination.getModel().getValueAt(row_index, col_index);
}
public static void main() {
ticketsql d = new ticketsql();
d.saveCustomers();
}
}
MySQL table is only updated with values from last row in table
Re: Problem with JTable and MySQL
I SOLVED this i move
before
Re: Problem with JTable and MySQL
You can mark the thread as solved with the "Thread Tools" dropdown box near the top of the page