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

 
 


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)      2 years and 4 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

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 Pages:
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
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  
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
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
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 
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 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
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
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 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
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
Mysql Alter Multiple Columns
Mysql Alter Multiple Columns       Mysql Alter Multiple Columns is used to modify the table definition... illustrate an example from 'Mysql Alter Multiple Columns'. To grasp this example
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
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
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
Getting Columns Names using Servlets
Getting Columns Names using Servlets   ... about the name of the columns without touching our database. As we... need to make any change in the program, you can easily understand in which
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
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
JTable
. And i'm not able to set value to a particular column. How can i do it? Please...JTable  Hi I have problems in setting values to a cell in Jtable... i enter id in a column. and i want to load other table columns the values
JTable Display Data From MySQL Database
. Here you will read about how to create a table in Java swing, how can you add column header's name, how can you show data into the table. How to create table in Java ? To create a table in Java Swing we will use the JTable and many
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
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   
Getting Number of Columns
Getting Number of Columns      ... of columns in the table without touching our database. As we are the programmers... change in the program, you can easily understand in which program you have
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.
JTable - JDBC
JTable   Hello..... I have Jtable with four rows and columns and i have also entered some records in MsSql database. i want to increase Jtable's rows automatically whenever i have records more than four rows. such as if i have
Create a Custom Cell Renderer in a JTable
that can be used to display the cells in a column. The JTable describes a specific.... To create a table cell renderer you need a JTable, so that  this program can... Create a Custom Cell Renderer in a JTable   
generate columns in file using tab delimeter - Swing AWT
one please help me how to generate the columns and rows using tab delimiter.(I...generate columns in file using tab delimeter   Hi, I have problem ........i have imported all the files in a directory using JFIleChooser
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
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
Select Employee and display data from access database in a jtable
Select Employee and display data from access database in a jtable  I there Iam a java beginner. I have to create a application where I can select a employee's name from a comboBox and the jtable will be filled with all
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
sum of all values in a column of jtable
sum of all values in a column of jtable  hey everyone, is there a code to display the sum of all values in a column of a jtable namely CARTtbl... columns and display the result in another column. import javax.swing.*; import
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
JTable populate with resultset.
JTable populate with resultset.  How to diplay data of resultset... is helpful in displaying data in tabular format. You can also edit data. JTable... not contain data. You can define your table as ? JTable table=new JTable(data
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
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
Not able to display jtable at runtime
Not able to display jtable at runtime  Hello, can anyone please help me. I am trying to create a dynamic table with checkboxes. Data are accessed... database properly. But I am not getting why it is not creating the table
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
Add XML to JTable
Add XML to JTable In this section, you will learn how to access the contents or data of xml document and display its information into the jtable. Java... node or you can say xml tags, use getFirstChild().getNodeValue() methods
JTable
, my problem is that this same table to see it only accepts a single line even if I have more than one view as he only accepts a single line ... I am asking you to rewrite my program so you can scroll and data exists in more than one line
Multi-line cells in the JTable - Java Tutorials
, asked me how to display a JTextArea within a cell of a JTable. I sensed it would... I had obtained their credit card details. All of them were wrong! Note... at all. A friend encouraged me a few years ago to write down all the things I had
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.