我是 Java 新手,正在做一个项目。我正在尝试使用 Netbeans 从 MS Access 检索数据。在我重新安装操作系统之前一切正常。现在我运行代码我得到这个错误。您的帮助和建议将不胜感激
java.sql.SQLException: No data found
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7138)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at connect.ConnectDB(connect.java:24)
at StaffLogin.formWindowOpened(StaffLogin.java:125)
at StaffLogin.access$000(StaffLogin.java:13)
at StaffLogin$1.windowOpened(StaffLogin.java:47)
at java.awt.Window.processWindowEvent(Window.java:1859)
at javax.swing.JFrame.processWindowEvent(JFrame.java:279)
at java.awt.Window.processEvent(Window.java:1820)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
这是代码,我也省略了“生成的代码”和“外观”。请让我知道是否需要这些。谢谢。
import java.sql.*;
import javax.swing.*;
public class StaffLogin extends javax.swing.JFrame {
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
/**
* Creates new form StaffLogin
*/
public StaffLogin() {
initComponents();
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
conn = connect.ConnectDB();
}
private void cmdloginMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
conn = connect.ConnectDB();
String u = txtusername.getText();
String p = txtpassword.getText();
String sql = "SELECT * FROM Staff_Table WHERE Firstname='" + u+"' and Password='"+ p+"'";
try{
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
if (rs.next()){
JOptionPane.showMessageDialog(null,"Correct Password");
Interface i = new Interface();
i.setVisible(true);
}
else
JOptionPane.showMessageDialog(null,"Invalid Username or Password");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new StaffLogin().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton cmdlogin;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField txtpassword;
private javax.swing.JTextField txtusername;
// End of variables declaration
}