Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Problem with JTable and MySQL

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Problem with JTable and MySQL

    I have a problem when updating MySQL database with values from JTable
    when i run this 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


  2. #2
    Junior Member
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Problem with JTable and MySQL

    I SOLVED this i move
    pstm.executeUpdate();
    before
    index++;

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default 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

Similar Threads

  1. problem with JTable
    By deependeroracle in forum AWT / Java Swing
    Replies: 3
    Last Post: March 17th, 2012, 09:41 AM
  2. Problem with Java/MySQL query...
    By RiskyShenanigan in forum JDBC & Databases
    Replies: 2
    Last Post: March 28th, 2011, 03:50 AM
  3. [SOLVED] JTable Problem
    By aussiemcgr in forum Java Theory & Questions
    Replies: 0
    Last Post: October 15th, 2010, 04:33 PM
  4. Connectivity problem:MySQL and Java
    By Pragya in forum JDBC & Databases
    Replies: 2
    Last Post: January 22nd, 2010, 03:58 AM
  5. Problem of getting result than SQL to JTable
    By MS_Dark in forum Exceptions
    Replies: 1
    Last Post: March 10th, 2009, 06:26 AM