Janki
ABOUT Jtable
1 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners

My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql .

How can retrive Data in Jtable from Mysql Database in Net Beans**

View Answers

February 9, 2011 at 11:50 AM


Retrieve data in JTable from Mysql database

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

MySql Database Configuration In NetBeans









Related Pages:
ABOUT Jtable
ABOUT Jtable  My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql . How can retrive Data in Jtable from Mysql Database in Net Beans
JTable - Java Beginners
JTable search example  I've problem about JTable, i wan to search records when i types words in JTable cell,can u give the source code.I'm Beginner and i start begins learning java programming.Please send the example into my
JTable populate with resultset.
JTable populate with resultset.  How to diplay data of resultset using JTable?   JTable is component of java swing toolkit. JTable class is helpful in displaying data in tabular format. You can also edit data. JTable
Java: Adding Row in JTable
Java: Adding Row in JTable   how about if we already have the JTAble created earlier. And i just found nothing to get its DefaultTableModel, thus, I can't call insertRow() method. Is there any work around for this? I found
JTable
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
JTable
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
jtable
jtable  hi Sir i am working netbeans IDE,I have a jtable when i insert values in jtable then i am unable to print all inserted values,For eg if i insert 1,2,3,4,5,6,7,8 values then , i am getting output
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
Packing a JTable Component
Packing a JTable Component       In this section you will learn about the packing of  a JTable by adjusting it in the center.  Description of program: This program
JTable
JTable  Hi I have problems in setting values to a cell in Jtable which is in a jFrame which implements TableModelListener which has a abstract method tableChanged(TableModelEvent e) . I'll be loading values from data base when
JTable
"}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane
Shading Columns in JTable
Shading Columns in JTable       Earlier you have read about the shading of  the rows in JTable. So, you are now capable for setting the shading the column
Multi-line cells in the JTable - Java Tutorials
the rows. I spent about an hour delving through the source code of JTable...Multi-line cells in the JTable 2002-04-11 The Java Specialists' Newsletter [Issue 045] - Multi-line cells in the JTable Author: Dr. Heinz M. Kabutz
Create a Custom Cell Renderer in a JTable
Create a Custom Cell Renderer in a JTable       After getting the knowledge about the JTable... cell renderer in a JTable component. Here, first of all you will know about
Setting Cell Values in JTable
values in JTable component. For this you must have the some previous knowledge about JTable. A cell is known as the format of  a row and a column in ... Setting Cell Values in JTable     
Setting the Column Header in JTable
Setting the Column Header in JTable       In the previous section, you have learnt about the creation of JTable without column headers. In this example you will learn
About java
About java   how we insert our database data into the jTable in java or how we show database content into the JTable... ); } } catch(Exception e){} JTable table = new JTable(data, columnNames
Setting Tool Tips on Cells in a JTable
Setting Tool Tips on Cells in a JTable   ... the tool tips in the cells in a JTable component. So, you will be able to know about the tool tips. The tool tips are most common graphical user interface
Removing a Row from a JTable
Removing a Row from a JTable       After inserting the data in a JTable, if you wish... the JTable. For removing the data of row from JTable, you will remove it from
Java JTable
about Java JTable, just click http:/www.roseindia.net/java/example/java/swing... Java JTable      ..., optionally allowing the user to edit the data. JTable does not contain or cache data
Shading Rows in JTable
Shading Rows in JTable       You have learnt about the JTable components and its... the shading rows in JTable. But, the question arises what is shading?.  Shading
jtable problem
jtable problem  how to make a cell text hypertext
JTABLE OF JAVA
JTABLE OF JAVA  i have a jtable in java,i have used checkbox in jtable. now i want to add(submit) only those records that i have checked by checkbox how? i want small example with coding
Jtable-Java
Jtable-Java  Hi all,I have a Jtable And i need to clear the data in the table .I only Need to remove the data in the table.not the rows.Please help me
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
sum in JTable
sum in JTable  how to calculate sum from JTable's one field like total
JTABLE Issue
JTABLE Issue  Hi Eveyone, I am developing a small application on Swing-AWT. I have used JTABLE to show data. There is "input field" and "search... on basis of input data provided in input field. For JTABLE is on some other
Setting the Height and Width of Rows and columns in JTable
in JTable. Earlier, you have read about the JTable that contains the data in rows... Setting the Height and Width of Rows and columns in JTable... and width for containing the data. JTable provides some specified height
jtable query
jtable query  I need a syntax...where i could fetch the whole data from the database once i click the cell in jtable...and that must be displayed in the nearby text field which i have set in the same frame
java jtable
java jtable  Hello Sir, I am developing a desktop application in which i have to display database records in jtable .now I want to read only... that in jtable. plz help me with the code
JTable Display Data From MySQL Database
JTable Display Data From MySQL Database In this section we will discuss about... will describe you the displaying of data of a database table into a JTable. Here you will read about how to create a table in Java swing, how can you add
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
REPORT WITH JTABLE
(Exception e){} JTable table = new JTable(data, columnNames); JScrollPane scrollPane
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... { JFrame f; JPanel p; JLabel l; JTextField tf; JButton btn; JTable tb
This JDK Tutorial shows you how to wrap text inside cells of a JTable
three years ago to the day, I wrote about Multi-line cells in the JTable...JDK Tutorial - Multi-line cells in JTable in JDK 1.4+ This JDK Tutorial shows you  how to wrap text inside cells of a JTable. 2005-04-14 The Java
JTable - Swing AWT
JTable row selection event   Hi, it will be great if someone can share an example of row selection event in JTable
JTable hold different components
JTable hold different components  create Jtable with two coloums,one coloumn is combobox and other normal
JTable in java - Java Beginners
JTable in java  Sir , I have created an application with a JTable showing the records of an MS Access database table. On the same frame I have... given one , JTable table; ....... .... table.print(); Here the error
JTable - Java Beginners
JTable  can we merge two cells of one row in jtable
restrict jtable editing
restrict jtable editing  How to restrict jtable from editing or JTable disable editing?   public class MyTableModel extends...){ return false; } }   Disabling User Edits in a JTable Component
regarding JTable - JDBC
regarding JTable  how to populate a JTable with mysql data after clicking JButton please explain with the example
JAVA DATABASE CONNECTION WITH JTABLE
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector
jtable query compare with date
jtable query compare with date  how to transfer daytable data to monthtable when complete a month
Jtable with servlet - Java Beginners
Jtable with servlet   Actually I have embedded the html... time I want the JTable to display the record saved in the database,the JTable... of the page and the bottom half will consists of JTable to display the record information

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.