About java

About java

how we insert our database data into the jTable in java or

how we show database content into the JTable in java

View Answers

December 6, 2010 at 11:36 AM

Hi Friend,

Try the following code:

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

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 data");
    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(450,200);
    frame.setVisible(true);
    }
  catch(Exception e)
    {}
  }
}

Thanks









Related Tutorials/Questions & Answers:
About Java
About Java  Hi, Can anyone tell me the About Java programming language? How a c programmer can learn Java development techniques? Thanks   Hi, Read about java at http://www.roseindia.net/java. Thanks
about java
about java  how to get the value from the user like c, c++ program pls explain with example for me
Advertisements
About java
About java   how we insert our database data into the jTable in java or how we show database content into the JTable in java   Hi Friend,ADS_TO_REPLACE_1 Try the following code: import
about J2EE. - Java Beginners
about J2EE.  I know only core Java ... what chapter I will be learn to know about J2EE
about jboss - Java Beginners
about jboss  can you please explain about jboss...how to deploy,where the temp and lock is there...total information about jboss to use in java message services(JMS
about J2EE. - Java Beginners
about J2EE.  I know only core Java ... what chapter I will be learn to know about J2EE.  Hi Friend, Please visit the following link: http://www.roseindia.net/ Thanks
About basics - Java Beginners
About basics  Why we are typing java program in text editor? Why we are running the java program in command prompt
Ask about java
Ask about java  Create a java program for add and remove the details of a person, which is not using by database, a simply java program. If possible, please wil it in switch case
about swings - Java Beginners
about swings   Dear sir,Good evening, i am doing mca sir,i am doing the project in swings,so plz provide the material about swings sir...: http://www.roseindia.net/java/example/java/swing/ Hope
about enum - Java Beginners
about enum  hi all, please tell me about "enum" and explain with example. And its use in OOP. Thanks
about c and java
about c and java   i need java and c language interview and objective questions with answers for the fresher.please provide to me   Please visit the following links: http://www.roseindia.net/java/ http
about java - Java Beginners
about java  hello, being a begineer in Java i would like know that as we read the value entered by user through cin>> in c++ how we did it with java.  Hi Friend, There are lot of ways to input data.You can use
Questions about Java's String pool
Questions about Java's String pool  Questions about Java's String pool
about package - Java Beginners
about package  as i am programming a question based on creating own... in the root directory.In my system java is installed in c:\ibm\java142\bin how can i run...://www.roseindia.net/java/master-java/java-package.shtml Hope
about interface - Java Beginners
about interface  can anyone explain to me the implementation of the given line Set si=new HashSet(); Problem is that Set is an interface...://www.roseindia.net/java
about array in java
about array in java  speed of a vehicle is measured using the total time and the distance by using the equation given bellow speed(km/hour)=distance... Vehicle 02 = 5 hours Write a JAVA class to represent the Vehicle. The program should
about JAVA - Java Beginners
about JAVA  i have to create a program that will sort the given numbers using bubble sort. the user will enter the number of inputs as well...; } } } } } ------------------------------------------- Read for more information, http://www.roseindia.net/java
about coding - Java Beginners
about coding  hello sir, I want to create session expair, when user is not enter anything in login page session wil expair after 10 min.if user enter its go to success page.plz send me full code about this. thanks
About inheritanance in JAVA
About inheritanance in JAVA  What is need foe the Inheritance in though we can access any method of any class declared publicly in simple class calling
About Java - Java Interview Questions
About Java  what is edition of java? versions of weblogic? what r the webserver applications used in your application
about instance of java
about instance of java  1> what is an instance 2> what is an object 3>what is difference between above two   Hi Friend, An Instance creates the reference of an object. An object is a run time entity
about JVM - Java Beginners
about JVM  Hello Rose india.net team I want to ask that why JVM is platform dependent is it automatically installs whenever we install jdk or is it automatically installed whenever we install operating system on our machine
Java Example projects about STRUTS
Java Example projects about STRUTS  Hai... I completed MCA but i have no job in my hands. But i do some small projects about STRUTS. Please send me some example projects about STRUTS.   Please visit the following link
About java and JDBC
About java and JDBC  Hello sir, I am doing project on java thats on swings,and using the dbase as MSSQL. what i want to know is i had created a name ,textfield ,calender(for DObirth selection), this is displayed in GUI
About java and JDBC
About java and JDBC  Hello sir, I am doing project on java thats on swings,and using the dbase as MSSQL. what i want to know is i had created a name ,textfield ,calender(for DObirth selection), this is displayed in GUI
about swing - Java Beginners
about swing  how implement a program of adding two numbers by entering two numbers separately by other user on the input dialog box and after that also show the result of the addition in other dialog box... your regardly
About Java arrays - Java Beginners
About Java arrays  Hello.........My question is can we create a two dimensional matrix using only one for loop
About Java
About Java This article is discussing about Java, which is a programming language developed by James Gosling at Sun Microsystems. Java now part of Oracle... about Java is listed below :ADS_TO_REPLACE_1 Around 1.1 billions desktop runs
about java swing - Java Beginners
about java swing   How to upload the pictures and photo on the panel in java swing ,plz help thank a lot.  Hi Friend, Try the following code: import java.awt.*; import java.io.*; import javax.swing.*; import
about project code - Java Beginners
about project code  Respected Sir/Mam, I need to develop an SMS... in commercial areas to send alerts to their customers about the events.... This can be developed using any kind of components using JAVA. The following
about regular expression - Java Beginners
about regular expression  Consider the grammar G: S -> ( L ) | a L -> L, S | S a) Eliminate the left-recursion from grammar G. b) Construct a recursive descent parser for G
about java swing - Java Beginners
about java swing   How to send date in data base if i use the combobox like as dd,mm,yyyy. plz reply thanx a lot  Hi Friend, Try the following code: import java.sql.*; import java.awt.*; import javax.swing.
about image convertion - Java Beginners
about image convertion  hello , this is srujani,i want code for the below task can you help me out. task is: When the Photos are Being Uploaded The Photos must be Automatically Resized to ?Web Large? Format
about implements and extends - Java Beginners
about implements and extends  hello, class A extends B implements c // this is valid statement class A implements c extends B // this is invalid statement can u plz explain me why the 2nd statement is invalid even though
about networking program - Java Beginners
about networking program  Dear Sir, i'm programing client side application where i've to convert data in to hex and then in to ascii format after that those data have to be transmitted to udp server in this case what kinda
About connection database oracle to java
About connection database oracle to java  Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked on sql it asked user ID and Password .so for ID i typed scott and password as tiger
About connection database oracle to java
About connection database oracle to java  Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked on sql it asked user ID and Password .so for ID i typed scott and password as tiger
About connection database oracle to java
About connection database oracle to java   I culdn't connect oracle datebase to java.when i compile the program it is ok. but when i clicked on sql it asked user ID and Password .so for ID i typed scott and password as tiger
About connection database oracle to java
About connection database oracle to java   I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked on sql it asked user ID and Password .so for ID i typed scott and password as tiger
About connection database oracle to java
About connection database oracle to java  **Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked on sql it asked user ID and Password .so for ID i typed scott and password
about value taken in java database - JDBC
about value taken in java database  how to take value from Serial port communication Hyperterminal to the java database
about static import - Java Beginners
about static import  Hello Friend below program is not running when i compile A.java it is compiling and i have put A.class in mypackage1. but when i compile B.class it is showing the compile time error on variable i. i want
How do beginners learn about Java?
How do beginners learn about Java?  Hi, I am beginner in Java and want to Java very fast. Is it possible to learn java fast? How do beginners learn about Java? Thanks   Hi, Beginners can start learning Java
About Object cloning. - Java Interview Questions
About Object cloning.  what is Object cloning? can u explain... is said to be object cloning.In java, it has to be done using clone() method. For more information, visit the following link: http://www.roseindia.net/java
about interview ques. - Java Interview Questions
about interview ques.  i give a interview for java.. they ask me. what is System.out.println(); what is its write ans...  Hi Friend, It is the syntax of Java used to display a string on the console window
Wants Suggestion about an issue. - Java Magazine
Wants Suggestion about an issue.  Hi all, I wish to develop a website like Social Networking Websites. For the development i think i should use Java Technology. So Request u guys to do suggest me what Design Pattern, What
about MVC in java - Java Interview Questions
about MVC in java  hi, In MVC Architecute can the Model and View can communicate directly or not?  Hi friend, For read in details MVC Architecture visit to : http://www.roseindia.net/struts/mvc
Question about parsing XML document with DOM in JAVA.
Question about parsing XML document with DOM in JAVA.  Hi, I need to parse a XML file witch has info about classes. So i have for each class to have its methods and for each method to get its parameters. I'm trying to do
about threading in java - Java Server Faces Questions
about threading in java  Hello Sir how can i write a program using threads and which need to check and compare the system date and time every day at certain time(eg:12 o clock in noon).. based on this comperision of time i
About zodiac sign in java - Java Beginners
About zodiac sign in java  Hello again.. I need help.. Our assgnment in programming is like this. Input your Bday and the output are your zodiac sign,, your chinese zodiac sign (year, ex: rat, pig, dragon etc..) and the element

Ads