all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns

all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns

i am 3rd year cs student in ethiopia. i have a view in my database schema so how can i create a jtable to look the view result in net beans

View Answers

January 11, 2011 at 4:25 PM

Hi Friend,

Try the following code:

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)
    {}
  }
}

Thanks









Related Tutorials/Questions & Answers:
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns  i am 3rd year cs student in ethiopia. i have a view in my database schema so how can i create a jtable to look the view result
create csv file in php in multiple columns
create csv file in php in multiple columns  i need create csv file in multiple columns like this: id name age date_added 1 john 23 2012-2-12 2 jane 25 2012-3-14 i can build csv file like this: id,name,age,date
Advertisements
create csv file in php in multiple columns
create csv file in php in multiple columns  i need create csv file in multiple columns like this: id name age date_added 1 john 23 2012-2-12 2 jane 25 2012-3-14 i can build csv file like this: id,name,age,date
how to insert multiple columns of a single row into my sql database using jsp
how to insert multiple columns of a single row into my sql database using jsp  hi sir, how to insert multiple columns of a single row into my sql database using jsp. when i click ADD ROW,rows are added.when i click submit
Selecting All Columns or Specific columns
Selecting All Columns or Specific columns  ... to create database and create a specific columns in MySQL .  CREATE Statement... to table columns. These values can be combined using different kinds
how to sort multiple key columns in CSV file - Java Beginners
how to sort multiple key columns in CSV file  Hi Any one can assist how to sort the multiple key columns in CSV file? Any example will be appreciated. Thanks
How to add a columns with a button set to a Jtable built with database result set
How to add a columns with a button set to a Jtable built with database result set  hi, i have to build a gui to display account numbers and account..., amount of each transaction etc. now i have stucked in the point of adding
Getting the Number of Rows and Columns in JTable
will learn how to get the number of rows and columns in JTable.  This program simply helps us for getting the number of rows and columns from the JTable by using... Getting the Number of Rows and Columns in JTable 
mysql alter table add multiple columns
mysql alter table add multiple columns  Hi, I have a table in database. I want to add multiple columns into existing table. What is the code for mysql alter table add multiple columns? Thanks   Hi, You can use
Setting the Height and Width of Rows and columns in JTable
Setting the Height and Width of Rows and columns in JTable... tutorial you will learn how to set the height and width of rows and columns... we are going to set the height and width of rows and columns in JTable
Mysql Alter Add Multiple Columns
Multiple Columns'. To understand this example, we create a table 'employees... Mysql Alter Add Multiple Columns       Mysql Alter Add Multiple Columns is used to modify
Mysql Alter Multiple Columns
Mysql Alter Multiple Columns       Mysql Alter Multiple Columns is used to modify the table... Columns'. To grasp this example we create a table employee1.The create table is 
Show multiple identical rows into JTable from database
Show multiple identical rows into JTable from database In this tutorial, you will learn how to display the multiple rows from database to JTable. Here..., then all the data associated with that name will get displayed into JTable rows
i want 2 columns to be deleted in mysql
i want 2 columns to be deleted in mysql  i want 2 columns to be deleted in mysql The tables having the columns have no mapping   Use the given query: ALTER TABLE table_name DROP col_name
How do I sort by mutiple columns that are in ArrayList using some comparable class
How do I sort by mutiple columns that are in ArrayList using some comparable class  Iam reading a csv file with 20 columns (all string types) in ArrayList after splitting them. I need to find how can I sort muti columns (i.e.
retrieve multiple columns values from multiple csv files in java
retrieve multiple columns values from multiple csv files in java  ...: file1.csv has 3 columns(VendorID,Name) file2.csv has 2 columns(VendorID,address)///// here VendorID is corresponding to file1.csv i want to retrive data from
SQL Alter Table Add Multiple Columns
demonstrate Alter Table Add Multiple Columns. The SQL Query create a table 'Stu... SQL Alter Table Add Multiple Columns       Alter Table Add Multiple Columns in SQL
SQL Alter Table Add Multiple Columns
demonstrate Alter Table Add Multiple Columns. The SQL Query create a table 'Stu... SQL Alter Table Add Multiple Columns       Alter Table Add Multiple Columns in SQL
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root"); Statement st=con.createStatement(); int i
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root"); Statement st=con.createStatement(); int i
Shading Columns in JTable
Shading Columns in JTable     ... in JTable.  In JTable component the shading columns are the simplest way...() method. The following code helps you for setting the shading columns in JTable
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
How to use JTable with MS-Access
How to use JTable with MS-Access   I have Three Column in Database (MS-Access). 1. Name 2. City 3. Contact I want to Display this data in JTable. How can I do it. I also want to EDIT and DELETE this Data
How to use JTable with MS-Access
How to use JTable with MS-Access   I have Three Column in Database (MS-Access). 1. Name 2. City 3. Contact I want to Display this data in JTable. How can I do it. I also want to EDIT and DELETE this Data
How To Display MS Access Table into Swing JTable - Java Beginners
How To Display MS Access Table into Swing JTable  How to Display... = md.getColumnCount(); for (int i = 1; i <= columns; i++) { columnNames.addElement( md.getColumnName(i) ); } while (rs.next()) { Vector row = new Vector(columns
ModuleNotFoundError: No module named 'columns'
'columns' How to remove the ModuleNotFoundError: No module named 'columns... to install padas library. You can install columns python with following command...ModuleNotFoundError: No module named 'columns'  Hi, My Python
how can i display a pdf file in a jtextarea
how can i display a pdf file in a jtextarea  I need to display a pdf file in a jtextfield or in a jtextarea.Atlest i need to displat it in a jframe.I have a button and while clicking on it ,i need to choose the pdf file and need
how can i display a editable result of form?
how can i display a editable result of form?  how can i display a editable result of form? i know how to display form result but the result... show the result but i can not modify the result. how can i display modifyable
How to find out the friend user between two columns in sql database
How to find out the friend user between two columns in sql database  Hi, Can any one please tell me ..how to find out the friend user between two columns in sql database? In other words i wanted to get the corresponding data from
creating columns and adding label and textfield in the columns in a jsp page
creating columns and adding label and textfield in the columns in a jsp page  I have create a jsp page with 3 columns.....each column has a title,3 label and corresponding 3 text fields....can u send me the code
Sql add columns
Sql add columns  How to add columns before existing columns. please help me out
Mysql Multiplication Columns
Mysql Multiplication Columns       Mysql Multiplication Columns is used to provide the column that is the outcome product of all the records in the respective columns
Mysql Multiplication Columns
that is the outcome product of all the records in the respective columns of a table... 'Mysql Multiplication Columns'. To understand the example we simply create... Mysql Multiplication Columns     
Sorting by multiple columns in AdvancedDataGrid in Flex4
Sorting by multiple columns in AdvancedDataGrid in Flex4: In this example you can see how we can sort a AdvancedDataGrid control using multiple column . We... by multiple columns in AdvancedDataGrid" height="422" width
Access Excel file through JDBC
Access Excel file through JDBC In this section, you will learn how to access excel file through Jdbc and display records in JTable. As you know Excel comes... all the data using ResultSet. To create a new ODBC Data Source, follow
how can i achieve multiple inheritance in java without using inheritance ?
how can i achieve multiple inheritance in java without using inheritance ?  how can i achieve multiple inheritance in java without using inheritance
how can i create a discussion forum?
how can i create a discussion forum?  how can i create a discussion forum for my e- mentoring site for women which can be used by a registered user only. i am using jsp and servlets and i am working with netbeans 6.8.
how to display multiple images on browser
how to display multiple images on browser  i want to display multiple images on brower including string values from sql database using jsp
how to display multiple images on browser
how to display multiple images on browser  i want to display multiple images on brower including string values from sql database using jsp
How can I create sessionfactory in Hibernate?
How can I create sessionfactory in Hibernate?  HELLO, How can I create sessionfactory in Hibernate? If you can explain me with example that would... with the links below: Hibernate 4 Hibernate Session Factory I hope
How to show multiple identicle rows from database on clicking search button to jtable
in the jtable .Suppose i enter name in search field which has two rows in the database table so i want to display both or any number of identicle rows in the jtable .I am...How to show multiple identicle rows from database on clicking search button
How to show multiple identicle rows from database on clicking search button to jtable
in the jtable .Suppose i enter name in search field which has two rows in the database table so i want to display both or any number of identicle rows in the jtable .I am...How to show multiple identicle rows from database on clicking search button
How to show multiple identicle rows from database on clicking search button to jtable
in the jtable .Suppose i enter name in search field which has two rows in the database table so i want to display both or any number of identicle rows in the jtable .I am...How to show multiple identicle rows from database on clicking search button
ModuleNotFoundError: No module named 'collect-columns'
named 'collect-columns' How to remove the ModuleNotFoundError: No module named... environment you have to install padas library. You can install collect-columns...ModuleNotFoundError: No module named 'collect-columns'  Hi, My
ModuleNotFoundError: No module named 'collect-columns'
named 'collect-columns' How to remove the ModuleNotFoundError: No module named... environment you have to install padas library. You can install collect-columns...ModuleNotFoundError: No module named 'collect-columns'  Hi, My

Ads