当我设置“ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE”然后当我运行我的应用程序时,我看不到我的应用程序的 Gui。我正在使用 Ucanaccess 驱动程序来连接我的 MS Access 数据库。问题出在哪里?请帮忙...
这是我的代码:
package javadatabase;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class gui extends Db{
JFrame fr;
JLabel fname;
JLabel lname;
JLabel age;
JTextField fntext;
JTextField lntext;
JTextField agetext;
JButton next = new JButton("Next");
JButton prev = new JButton("Prev");
JButton first = new JButton("First");
JButton last = new JButton("Last");
public gui(){
frame();
}
public void frame(){
fr = new JFrame();
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fr.setSize(600, 400);
fr.setVisible(true);
fname = new JLabel("نوم: ");
lname = new JLabel ("تخلص: ");
age = new JLabel ("عمر: ");
fntext = new JTextField(20);
lntext = new JTextField(20);
agetext = new JTextField(20);
JPanel panel = new JPanel();
panel.add(fntext);
panel.add(fname);
panel.add(lntext);
panel.add(lname);
panel.add(agetext);
panel.add(age);
panel.add(next);
panel.add(prev);
panel.add(first);
panel.add(last);
fr.add(panel);
try{
rs.next();
fntext.setText(rs.getString("Fname"));
lntext.setText(rs.getString("Lname"));
agetext.setText(rs.getString("Age"));
}catch(Exception ex){}
}
}
这是我的主要课程:
package javadatabase;
import java.sql.*;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class Db {
Connection con;
Statement st;
ResultSet rs;
public Db(){
connect();
}
public void connect(){
try{
con = DriverManager.getConnection("jdbc:ucanaccess://d:\\\\netbeansProjects\\\\db1.accdb");
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "select * from Table1";
rs = st.executeQuery(sql);
}catch(Exception ex) {}
}
public static void main(String[] args) {
//Look and feel
try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
catch (ClassNotFoundException e) {}
catch (InstantiationException e) {}
catch (IllegalAccessException e) {}
catch (UnsupportedLookAndFeelException e) {}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Db();
new gui();
}
});
}
}