jdbc and swing problem in netbeans

Ads
 

jdbc and swing problem in netbeans

i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent

View Answers

August 29, 2011 at 2:52 PM

import java.io.*;
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;

class JTableDatabase extends JFrame{
    ResultSet rs;
    JTableDatabase(){
    final Vector columnNames = new Vector();
    final Vector data = new Vector();
    JPanel panel=new JPanel();
    try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
    Statement st = con.createStatement();
    ResultSet rs= st.executeQuery("Select * from employee");
    ResultSetMetaData md = rs.getMetaData();
    int columns = md.getColumnCount();
    for(int i = 1; i <= columns; i++){
    columnNames.addElement(md.getColumnName(i));
    }
    while(rs.next()){
    Vector row = new Vector(columns);
    for(int i = 1; i <= columns; i++){
    row.addElement(rs.getObject(i));
    }
    data.addElement(row);
    }
   }
   catch(Exception e){}
   JTable table = new JTable(data, columnNames);
   JScrollPane scrollPane = new JScrollPane(table);
   panel.add(scrollPane);
   add(panel);
}
 public static void main(String arg[]){
    try{
    JTableDatabase frame=new JTableDatabase();
    frame.setSize(550,200);
    frame.setVisible(true);
    }
  catch(Exception e)
   {}
  }
}

Ads









Related Tutorials/Questions & Answers:
jdbc and swing problem in netbeans
jdbc and swing problem in netbeans  i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent
jdbc and swing problem in netbeans
jdbc and swing problem in netbeans  i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent
Advertisements
Java swing in NetBeans - Swing AWT
Java swing in NetBeans   thanks a lot sir for everything you answered for my last questions now sir i just have another 3 questions that is Q 1. i will specify a swing code for JTable using NETBEANS so would you tell me
java swing in netbeans
java swing in netbeans  how can create sub menu in java swing using netbeans?   Hi Friend, Try the following code: import javax.swing.*; public class CreateSubmenu { public static void main(final String args
jdbc problem
jdbc problem   hi my name is mohit...i am making a project in java.......i have made this code in netbeans...i have already entered the values..."); con = DriverManager.getConnection("jdbc:odbc:mohit"); stmt
problem in jdbc connection
problem in jdbc connection  when i am trying to insert into apache derby databse using java in netbeans an exceprion is thrown at run time like this:- java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver....what
Swing Problem on submission of button
Swing Problem on submission of button  How to close current frame (Frame1) and open a new frame (Frame2) already created and pass the data to frame2 from frame1 on the clicking of button in swing
problem in swing-awt
problem in swing-awt  I am doing project in core java and i am facing one problem. I have to add command prompt(terminal) to the fream at bottom but not getting the solution. So please help me. thanks and regards, Aakash
oracle connectivity problem with netbeans
oracle connectivity problem with netbeans  sir I am using oracle window version +net bean6.8. jam trying to connect net bean to oracle. for this after adding new driver(ojdbc6.jar) in services tab I got connectivity with oracle
java,jdbc,netbeans
java,jdbc,netbeans  can you tell me the program which read multiple dbf files and then insert those dbf files data in msaccess automatically
SQL STATEMENT in JDBC in NETBEANS IDE
SQL STATEMENT in JDBC in NETBEANS IDE  Iam using NETBEANS IDE. Iam developing a bank application. Using JDBC in SERVLETS For the withdraw function, "bal" and "ano" are user inputs when i wrote like, st.executeQuery("UPDATE
jdbc oracle connectivity problem
jdbc oracle connectivity problem  Hi All, I am trying to connect my swing application to oracle DB . but class.forname is giving error. Please suggest me if there is some different way to connect swing application to oracle
swing text field problem
swing text field problem  I want to navigate the content of text field from one class to another and viceversa through button but when I am getting the text from first class I am getting null value.please help me..here
swing text field problem
swing text field problem  I want to navigate the content of text field from one class to another and viceversa through button but when I am getting the text from first class I am getting null value.please help me..here
JDBC ODBC related problem
JDBC ODBC related problem  i WANT HELP RELATED TO JDBC CONNECTIVITY... con; con = DriverManager.getConnection("jdbc:odbc:Digambar... THE ERROR PART...... THE QUESTION N PROBLEM IS I WANT TO SELECTE PERTICULAR PAPER FROM
problem in inserting data in databases created in netbeans using jsp..
problem in inserting data in databases created in netbeans using jsp.. ... created table inside netbeans through sql editor.and tried to make a login page whose... = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root
Problem to get connection from DAO class to JDBC
Problem to get connection from DAO class to JDBC  package controller; import java.sql.Connection; import java.sql.DriverManager; public class... { String DRIVER="oracle.jdbc.driver.OracleDriver"; String URL="jdbc:oracle
problem in swing program for opening two windows with same login credentials
problem in swing program for opening two windows with same login credentials  I Face two problems while writing the code in swing program 1.i... representation problem is when i delete a node the tree is not automatically
NetBeans
NetBeans  Hi, I am Kundan I have made a project on NetBeans. And now I want to know that how can i run my project without NetBeans IDE,on other PC. Please help me it's important
NetBeans
NetBeans  Hi, I am Kundan I have made a project on NetBeans. And now I want to know that how can i run my project without NetBeans IDE,on other PC. Please help me it's important
netbeans
netbeans  In netbeans, there are choices of books with their price. you check the book you wanted then click the purchase.the output should be the book with the price then you will get the total price of the book you purchase.how
netbeans
netbeans  guysss m nt able to opemn ma netbeans ide.. no error msg s coming... wn i installed yesterday one msg came stating about some run time error... sm one plzzzzzz hlp me
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those... in a table. Use JDBC
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those... in a table. Use JDBC
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
swing
swing  Write a java swing program to delete a selected record from a table
swing
swing  How to make swing component auto-resizable when JFrame resize
problem in creating web application using servelet, jsp, jdbc and xml - JSP-Servlet
problem in creating web application using servelet, jsp, jdbc and xml  Using Servlet, JSP, JDBC and XML create a web application for a courrier...; Hi friend, For solving the problem visit to : http://www.roseindia.net
jdbc
jdbc  I can't run my jdbc program because it has error in this line: public static void main(String[] args) the error is:illegal static declaration in inner class would you please let me whats the problem? regards
webservice in Netbeans
problem at 17 th step while right clicking on the source code im not getting..... im using netbeans version 6.9.1 .. pls help me out... regards-- Harish Kumar
jdbc
define transactions  define transactions   Whenever a connection is created by using the JDBC, then by default it is in auto- commit mode...() method. If there arises any problem while committing then the set

Ads