Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to store resultset data in jtable.

Posted on 2012-08-11
3
Medium Priority
?
587 Views
Last Modified: 2012-08-14
We don't know the number of rows and columns returned. How to store it in Jtable.
How to modify the following code.
import java.sql.*;
import java.swing.*;
import java.awt.*;

class sqlselect
{
public static void main(String args[]) throws Exception
      {
            int rno;
            String sname,scity;

            Connection conn;      
            Statement stmt;
            ResultSet rs;

            //initialize and load the JDBC-ODBC Driver
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            
            //to get a datbase connection
            conn=DriverManager.getConnection("jdbc:odbc:schooldsn","","");
      
            //to create a statement object to execute SQL statement
            stmt=conn.createStatement();
            //Sends the sql statemtent to the DBMS & exec
              rs=stmt.executeQuery("select * from student");
         
          JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Object rowData[][] = {
                        { "Row1-Column1", "Row1-Column2", "Row1-Column3" },
                          { "Row2-Column1", "Row2-Column2", "Row2-Column3" }
                             };
          Object columnNames[] = { "Column One", "Column Two", "Column Three" };
          JTable table = new JTable(rowData, columnNames);
          JScrollPane scrollPane = new JScrollPane(table);
          frame.add(scrollPane, BorderLayout.CENTER);
          frame.setSize(300, 150);
          frame.setVisible(true);
     }
}
0
Comment
Question by:searchsanjaysharma
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 38284919
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 38290725
ok
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38291465
:)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question