craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > Events/Actions Post New Topic   Post A Reply
auto update from mysql printer friendly version
next newest post | next oldest post
Author Messages
hcir
Private

Gender: Male
Location: alaska
Registered: Oct 2006
Status: Offline
Posts: 7

Click here to see the profile for hcir Send email to hcir Send private message to hcir Find more posts by hcir Edit or delete this message Reply w/Quote
Posted Monday, October 2, 2006 @ 18:11:08  

looking for a full example of how to use threading to poll mysql. would like to update the quicktable every X seconds
Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Tuesday, October 3, 2006 @ 10:28:17  

This is a modified version of the basic table example located at

http://quicktable.org/tutorial/basic.htm

Code:

import javax.swing.*;
import quick.dbtable.*;
import java.sql.*;
import java.awt.event.*;

public class QuickTableFrame extends JFrame
{
public QuickTableFrame()
{
//set Frame properties
setSize(300,200);
setVisible(true);

//create a new quicktable
final quick.dbtable.DBTable dBTable1 = new quick.dbtable.DBTable();

//add to frame
getContentPane().add(dBTable1);

//set the database driver to be used, we are using jdbc-odbc driver
dBTable1.setDatabaseDriver("sun.jdbc.odbc.JdbcOdbcDriver");

/*
set the jdbc url,"quicktabledemo" is the data source we have created
for the database
*/
dBTable1.setJdbcUrl("jdbc:odbc:quicktabledemo");

// set the select statement which should be used by the table
dBTable1.setSelectSql("select * from employee");

//to create the navigation bars for the table
dBTable1.createControlPanel();

try
{
//connect to database & create a connection
dBTable1.connectDatabase();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}

//create a timer
Timer timer = new Timer(5000, new ActionListener() { //5000 = 5 sec

public void actionPerformed(ActionEvent evt) {

//refresh quicktable
try
{
//fetch the data from database to fill the table
dBTable1.refresh();
}
catch(SQLException e)
{
e.printStackTrace();
}

}
});

//start the timer
timer.start();

}

public static void main(String[] args)
{
//create a new table frame
QuickTableFrame myframe = new QuickTableFrame();
}
}


For more information about how to use swing timers, refer
http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html

hcir
Private

Gender: Male
Location: alaska
Registered: Oct 2006
Status: Offline
Posts: 7

Click here to see the profile for hcir Send email to hcir Send private message to hcir Find more posts by hcir Edit or delete this message Reply w/Quote
Posted Tuesday, October 3, 2006 @ 21:05:53  

Thanks for the reply. This is just what I was trying to figure out. I did have to mkae one very minor change; instead of

quick.dbtable.DBTable dBTable1 = new quick.dbtable.DBTable();

changed to

finaal quick.dbtable.DBTable dBTable1 = new quick.dbtable.DBTable();

THANKS AGAIN

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios