0

Hello everyone! I have been working on my school project and I have encountered problem linking jTable with a table in the sql server.Can anyone please help me regarding it.Please help me with the code on how to link the the table.

3
Contributors
2
Replies
9
Views
1 Year
Discussion Span
Last Post by JamesCherrill
0

This should work

String sql = "SELECT row1, row2, row3 mysqltable";
                  ResultSet rs = stmt.executeQuery(sql);  
      //STEP 1: Extract data from result set
      while(rs.next()){
         //Retrieve by column name
         int row1  = rs.getInt("row1");
         String row2 = rs.getString("row2");
         String row3 = rs.getString("row3");
         //STEP 2 create an object array of the mysql data
    Object[] row = {row1,row1,row3};
    //STEP 3: add object array to jtable
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        model.addRow(row);
        }

work out the rest

Edited by zaraki: ..

0

Hi Zaraki (and Kriti)

Please note that it is DaniWeb's policy that posters should show some effort before we give them help. "Please do my homework for me" posts are usually either ignored or penalised.

Having said that... Z's post is good in that it points OP in the right direction without just giving a solution on a plate.

JC _ Moderator

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.