JTable...............

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeep84
    New Member
    • Sep 2007
    • 37

    #1

    JTable...............

    Hi........ to all

    I hav created the table in the applet window using JTable... i hav to store the retrived data from database in the table..consider if the table contains 3rows i hav insert all the 3 rows ..... Is it possible... if so.. can u explain me..how.....


    Regards
    Pradeep
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by pradeep84
    Hi........ to all

    I hav created the table in the applet window using JTable... i hav to store the retrived data from database in the table..consider if the table contains 3rows i hav insert all the 3 rows ..... Is it possible... if so.. can u explain me..how.....


    Regards
    Pradeep
    Of course it's possible. When the saved button is clicked, just execute an insert statement.

    Comment

    • pradeep84
      New Member
      • Sep 2007
      • 37

      #3
      Originally posted by r035198x
      Of course it's possible. When the saved button is clicked, just execute an insert statement.
      Thanks..

      can u explain with a small example .....

      Regards
      Pradeep

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by pradeep84
        Thanks..

        can u explain with a small example .....

        Regards
        Pradeep

        What do you have so far?

        Comment

        • pradeep84
          New Member
          • Sep 2007
          • 37

          #5
          Originally posted by r035198x
          What do you have so far?
          Sorry sir.. yesterday due to network problem.. i can't able to continue the discussion..... . i hav to insert data into the table....
          consider if the database contains 3 rows.. i hav to insert all the three rows...
          can u say how to get all the rows.. from the database..

          Code:
          import java.io.*;
          import java.sql.*;
          import java.awt.*;
          import java.awt.event.*;
          import sun.jdbc.odbc.*;   
          import javax.swing.*;
          
          public class Tab extends Frame implements ActionListener
          {
             JTable table;
             Label l1;
             Button view,exit;
             Connection con;
             ResultSet rs;
             Statement stmt;
             String s,M;  
           public Tab()
                   
           {
               super("Table");
              setSize(700,700);
              setLayout(null);
              setBackground(new java.awt.Color(245, 117, 105));
              
               table = new JTable(7,8);
               l1=new Label("TABLE");
               l1.setBounds(20,60,100,70);
               table.setBounds(30,180,650,114);
               exit= new Button("Exit");
               exit.addActionListener(this);
               exit.setBounds(360,580,100,40);
               
               
               add(l1);
               add(table);
                add(exit);
               setVisible(true);
               
               
               
           addWindowListener(new WindowAdapter(){
            public void WindowClosing(WindowEvent w) {System.exit(0);}});
              }
           
           
           
           public void actionPerformed(ActionEvent ae)
          {
           int flag=0;
           if(ae.getSource()==view)
          {
               
          try 
          {
               
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                con=DriverManager.getConnection("jdbc:odbc:prism");
                stmt=con.createStatement();
                rs=stmt.executeQuery("select * from Melting");
          
               
          [B]      while(rs.next())
               {
          
                  s=(rs.getString(1));
          
                 }    [/B] 
          }
          catch(ClassNotFoundException e)
          {
            System.out.println(e);
          }    
          catch(SQLException e)
          {
            System.out.println(e);
          }
           }
            if(ae.getSource()==exit)
            {
               System.exit(0);
            }
           }
            public static void main(String args[]) 
          {
               
                Tab pu=new Tab();
            }
          }

          Comment

          Working...