Using existing Connection with
Quicktable
This example uses existing Connection object with quickTable.
import javax.swing.*;
import quick.dbtable.*;
import java.sql.*;
public class ExistingConnectionFrame extends JFrame
{
public ExistingConnectionFrame(Connection dbConnection)
{
//set Frame properties
setSize(300,200);
setVisible(true);
//create a new quicktable
quick.dbtable.DBTable dBTable1 = new
quick.dbtable.DBTable();
//add to frame
getContentPane().add(dBTable1);
dBTable1.setConnection(dbConnection);
// 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
{
//fetch the data from database to fill
the table
dBTable1.refresh();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
try
{
//Load your jdbc driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch( ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
//create a database connection
Connection dbConnection =
DriverManager.getConnection ("jdbc:odbc:quicktabledemo");
//create a new table frame
ExistingConnectionFrame myframe = new
ExistingConnectionFrame(dbConnection);
}
catch(SQLException e)
{
e.printStackTrace();
}
}
} |