Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mohammed oumer adem
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns
1 Answer(s)      3 years and 8 months ago
Posted in : JDBC


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


Advertisement
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
Selecting All Columns or Specific columns
can be as simple as a single constant. Expressions may use function calls.... These can be use columns name or plane text string . Example... Selecting All Columns or Specific columns  
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
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... to set the height and width of rows and columns in JTable. This table has
Mysql Alter Multiple Columns
Mysql Alter Multiple Columns       Mysql Alter Multiple Columns is used to modify the table... The Tutorial illustrate an example from 'Mysql Alter Multiple Columns'. To grasp
Mysql Alter Add Multiple Columns
Mysql Alter Add Multiple Columns       Mysql Alter Add Multiple Columns is used to modify the table and add multiple columns to the specified table. Understand with Example
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.
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
SQL Alter Table Add Multiple Columns
Add Multiple Columns. The SQL Query create a table 'Stu_Table' with table... SQL Alter Table Add Multiple Columns       Alter Table Add Multiple Columns in SQL
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
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
Add Multiple Columns. The SQL Query create a table 'Stu_Table... SQL Alter Table Add Multiple Columns       Alter Table Add Multiple Columns in SQL
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 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
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
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
Use multiple catch statement in single jsp
exception so we can use multiple catches or Exception class (base class of all... Use multiple catch statement in single jsp       In java a single try can have multiple
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
Advertisements
 

 

 

DMCA.com