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

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 7 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.
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
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
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
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
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
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
Mysql Multiplication Columns
that is the outcome product of all the records in the respective columns of a table... Multiplication Columns'. To understand the example we simply create a table... Mysql Multiplication Columns     
Mysql Multiplication Columns
the column that is the outcome product of all the records in the respective columns... 'Mysql Multiplication Columns'.To understand the example we simply create... Mysql Multiplication Columns   
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
Sql add columns
Sql add columns  How to add columns before existing columns. please help me out
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
How can i use Facebook connect button
How can i use Facebook connect button  Please to meet you all guys I wonder how can i use this Connect to facebook for me to post in a particular... http://likekhevy4.blogspot.com/ How can i apply this kind of comment with "Connect
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 insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array  i am using netbeans 7.0 ,with struts 1.3.8 and i want to insert multiple images in mysql database ,with use
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 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 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
How can i display the distance of a line drawing randomly?
How can i display the distance of a line drawing randomly?  How can i display the distance of a line drawing randomly
how can i create a data grid - Java Beginners
how can i create a data grid  Nice to ur respose...thnks all of u plz help me i want make a datagrid but i have no idea about this how can i create datagrid. and how can i connect to the database plz help me give
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
Can i use Scriptlets inside javascript,if so how?
Can i use Scriptlets inside javascript,if so how?  Can i use Scriptlets inside javascript,if so how
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 use toggle button in my application
how can i use toggle button in my application  i want a on/off toggle button by dragging left-right..not by pressing on button
Advertisements
 

 

 

DMCA.com