Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Display database values into JTables

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Thanked 0 Times in 0 Posts

    Default Display database values into JTables

    Hey guys i would love someone to help me with my project. I am trying to display all of the data from a database to a jtable using Eclipse.
    When i run this code i dont get any errors and nothing shows on the jtable.
    I watched and followed this guy's video guide ( Java prog#5. JTable- Populate JTable data from database in java Netbeans and Sqlite (mysql) - YouTube )
    and i downloaded this file rs2xml.jar
    *** I am new to programming and still working on my skills ***
    Thanks (Heads up)

    package foodpackage;
    import java.awt.Color;
    import java.awt.EventQueue;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableModel;
    import net.proteanit.sql.DbUtils;
     * @author sa00366
    public class Admin {
    	String MSAccessDriver = "sun.jdbc.odbc.JdbcOdbc ".trim();
    	String MyDatabase = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\db\\Database.mdb";
    	Connection con = null;
    	Statement st = null;
    	ResultSet rs;
    	PreparedStatement pst = null;
    	private JFrame frmAdminis;
    	private JTable table;
    	private JButton btnButton;
    	 * Launch the application.
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					Admin window = new Admin();
    				} catch (Exception e) {
    	 * Create the application.
    	public Admin() {
    	public void Update_Table() {
    		try {
    			String sql = "select * dog";
    			rs = st.executeQuery(sql);
    			String db = "jdbc:odbc:Animal"; // db = database string stored
    											// in the database
    			con = DriverManager.getConnection(db);
    			st = con.createStatement();
    		catch (Exception ex) {
    	 * Initialize the contents of the frame.
    	private void initialize() {
    		frmAdminis = new JFrame();
    		frmAdminis.setTitle("Title ");
    		frmAdminis.setBounds(100, 100, 1048, 547);
    		table = new JTable();
    		table.setBounds(61, 76, 794, 226);
    		btnButton = new JButton("button");
    		btnButton.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    		btnButton.setBounds(61, 391, 200, 50);
    	private static class __Tmp {
    		private static void __tmp() {
    			  javax.swing.JPanel __wbp_panel = new javax.swing.JPanel();

  2. #2
    Junior Member
    Join Date
    Aug 2013
    Thanked 0 Times in 0 Posts

    Default Re: Display database values into JTables

    Try making a JList out of the model you get from that DbUtils, then use that JList in your setModel.

    For example:

    JList myList = new JList(DbUtils.resultSetToTableModel(rs));

Similar Threads

  1. buttons and buttongroups send values to database
    By Light Mike in forum JDBC & Databases
    Replies: 2
    Last Post: August 22nd, 2012, 04:49 AM
  2. how to plot a line graph by reading the values from database?
    By priti in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2012, 01:39 AM
  3. [SOLVED] compare form values with database values
    By VaniRathna in forum Java Servlet
    Replies: 2
    Last Post: October 24th, 2011, 02:48 AM
  4. Using jbutton to write to jtextfield values to database
    By Sociopath in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 23rd, 2011, 10:53 PM
  5. [SOLVED] Need to display multiple images from database on a webpage
    By raghuprasad in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: May 13th, 2009, 03:15 AM

Tags for this Thread