我为应用项目创建了一个数据库,我实现了应用程序的所有窗口,当我尝试将德比数据库链接到我的项目时,它不起作用!我已经编写了几个代码来链接数据库,但仍然无法工作(起初我使用的数据库已经创建,然后我尝试将嵌入式数据库链接到我的项目,但没有)这里有什么尝试!!我错过了什么吗?
try { Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Connection cnx = DriverManager.getConnection("jdbc:derby:C:\\Users\\user pc\\AppData\\Roaming\\NetBeans\\Derby\\projetihm","root","root");
Statement stm= cnx.createStatement();
String qst = "Select * from ROOT.USERAPP where username='"+uname.getText()+"'";
ResultSet rst = stm.executeQuery(qst);
if (rst.next())
{ JOptionPane.showMessageDialog(null, "Connexion successful");
}
else {JOptionPane.showMessageDialog(null, "Wrong password or username"); }
}
catch (Exception e ) {};
我也试过这个
Try{ Connection cnx= DriverManager.getConnection("jdbc:derby://localhost:1527/projetihm","root","root");
Statement stm= cnx.newStatement();
ResultSet rst = stm.executeQuery("Select * From userapp ");
while (rst.next())
if (rs.getString(1).equals(uname.getText()) && rst.getString(2).equals(pass.getText()))
{ JOptionPane.showMessageDialog(null, "Wrong password or username try again");
}
else {JOptionPane.showMessageDialog(null, "Wrong password or username try again"); }
}
catch (Exception e ) {};
答案 0 :(得分:1)
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Connection cnx = DriverManager.getConnection("jdbc:derby://localhost:1527/projetihm","root","root");
Statement stm= cnx.createStatement();
ResultSet rst = stm.executeQuery("Select * From userapp");
while (rst.next())
if (rst.getString(1).equals(uname.getText()) && rst.getString(4).equals(pass.getText()))
{ this.setVisible(false);
all a = new all(); a.setVisible(true);
}
else {JOptionPane.showMessageDialog(null, "Wrong password or username "); }
} catch (Exception e) { e.printStackTrace(); }