How to store resultset data in jtable.

Posted on 2012-08-11
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
            //to get a datbase connection
            //to create a statement object to execute SQL statement
            //Sends the sql statemtent to the DBMS & exec
              rs=stmt.executeQuery("select * from student");
          JFrame frame = new JFrame();
            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);
Question by:searchsanjaysharma
    LVL 86

    Accepted Solution


    Author Closing Comment

    LVL 86

    Expert Comment


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    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 …
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now