CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2007
    Posts
    122

    My Problem With Jtable

    hi,
    i have problem with jtable to display data from db into table and here's the code that diplay data in console so what is the update on code to display data in jtable

    Code:
    import java.sql.*;
    
    public class JdbCgetConnection2{
    
      public JdbCgetConnection2(){
         getConnection();
         System.out.println("Connection establish");
         System.out.println("---------------------");
      }
    
    
      public static void main(String []args){
       new JdbCgetConnection2();
    
       ResultSet allInfo = null;
       try{
       allInfo = getAllInformation();
    
    
       while(allInfo.next()){
       String s = allInfo.getString("id1");
       String s1 = allInfo.getString("name");
    
       System.out.print(s+"\t");
       System.out.print(s1+"\t");
       System.out.println();
    
       }//end of while stmt
       }//end of try stmt
    
       catch(Exception e){
    	   System.out.print("no");
    
       }//end of catch stmt
    
    
    
    
    
       }
    
    
      //get Connection
      private static Connection getConnection()
    		{
    		Connection con = null;
    		try
    		{
    		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    		String url = "jdbc:odbc:db1";
    		con = DriverManager.getConnection(url);
    		}
    		catch (ClassNotFoundException e)
    		{
    		System.out.println(e.getMessage());
    		System.exit(0);
    		}
    		catch (SQLException e)
    		{
    		System.out.println(e.getMessage());
    		System.exit(0);
    		}
    		return con;
    		}
    
    
     //get all Information from table
     private static ResultSet getAllInformation()
    		{
    		Connection con = getConnection();
    		try
    		{
    		Statement s = con.createStatement();
    		String select = "Select id1,name "+"from Tb_Info";
    		ResultSet rows;
    		rows = s.executeQuery(select);
    		return rows;
    		}
    		catch (SQLException e)
    		{
    		System.out.println(e.getMessage()+"error here");
    		}
    		return null;
    		}
    
    
    }

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: My Problem With Jtable

    Data for JTable is held in a TableModel. You should create a TableModel for your data (subclass AbstractTableModel) and add it to the table.

    See How To Use Tables and Creating A Table Model.

    Today, most software exists, not to solve a problem, but to interface with other software...
    I.O. Angell
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Feb 2007
    Posts
    122

    Re: My Problem With Jtable

    can u give me simple update on the previous code?

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: My Problem With Jtable

    Quote Originally Posted by ahmed17
    can u give me simple update on the previous code?
    No. Why would we write your code for you? If you want to learn, follow the tutorial. If you get stuck, or don't understand something, ask and we'll try to help you.

    Teachers open the door, but you must enter by yourself...
    Chinese proverb.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Feb 2007
    Posts
    122

    Re: My Problem With Jtable

    thanks for you, but i will say to you why i want simple example , first i spend 5 days in this problem , i take object from jtable and take row in array and pass array with array of column name to the constructor of jtable but not work and i do the same idea before with jtable to test how jtable work and i do the following , make 2 array one array strore not from db but in array itself and another stroe coulmn name so it work and in this case not work so wat is the problem ?

  6. #6
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: My Problem With Jtable

    I can't tell what your problem is from that garbled description. I suggest you follow the tutorial and get one of the tutorial examples working, then you can modify it for your own requirements.

    If you want help on something specific, post up the relevant code and the full text and stack trace of any error messages, and explain what the code was trying to do, what the expected result was, and what happened. Saying your code 'did not work' is just a waste of time without the details above.

    They know enough who know how to learn...
    J. Adams
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  7. #7
    Join Date
    Feb 2008
    Posts
    966

    Re: My Problem With Jtable

    Wow, I think that is the longest run-on sentence in the history of man.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured