我正在使用JAVA,Netbeans IDE和SQL Server 2008.所以,我想在我的表单上显示一条记录。我收到的消息是" Driver Error"在表单出现之前。我怎么解决这个问题? **
这是我的代码
package javaapplication;
import java.sql.*;
import javax.swing.JOptionPane;
public class EmployeeInfo extends javax.swing.JFrame {
Connection cn;
Statement stm;
ResultSet rs;
String url = "jdbc:odbc:EMPDB";
public EmployeeInfo() {
initComponents();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn = DriverManager.getConnection(url);
stm = cn.createStatement();
rs = stm.executeQuery("select * from employee");
while (rs.next())
{
txtID.setText(rs.getString(1));
txtName.setText(rs.getString(2));
txtPhone.setText(rs.getString(3));
}
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(this, "SQL Error");
}
catch(ClassNotFoundException cnfe)
{
JOptionPane.showMessageDialog(this, "Driver Error");
}
}
public static void main(String args[]) { /* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new EmployeeInfo().setVisible(true);
}
});
}
我正在使用此表单,它有这个问题。 我怎么能恢复它?