i really want to learn java with your help
this is my code
Connect class
import java.sql.*;
import javax.swing.*;
public class Connect {
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
public static Connection ConnectDB(){ // to return a Connection object
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection ("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=Database1.mdb");
//JOptionPane.showMessageDialog(null, "Connected");
return conn; // <--------------
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
this code shows the data from access database to jtable using netbeans IDE
this is similar to formload in vb programming
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
conn = Connect.ConnectDB();
String sql =("select * from table1") ;
try {
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (Exception ex) {
System.out.print(ex);
}
}
but i need to retype the code again after the message box update or delete. so how to create a method so that i will just call the method of showing all the data. i have tried some code but doesn't show me error or data
but if i use jtable events property change the error is
private void jTable1PropertyChange(java.beans.PropertyChangeEvent evt) {
// TODO add your handling code here:
conn = Connect.ConnectDB();
String sql =("select * from table1") ;
try {
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (Exception ex) {
System.out.print(ex);
}
}
1. java.sql.SQLException:[Microsoft][ODBC Microsoft Access Driver] Too many Client tasks.
2. java.lang.NullPointerException

New Topic/Question
Reply




MultiQuote




|