我做了个登陆界面 无论怎样都不能实现 Netbeans也不报错~~~我很无奈 求大神解惑
代码如下
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==okButton)
{
Name=name.getText();
Pwd=pwd.getText();
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/user?user=root&password=900511";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
String sql = "select * from users where name='" + Name+ "' and pwd = '" + Pwd + "'";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
{
JFrame main = Lib20App.getApplication().getMainFrame();
main.dispose();
UserWnd userwnd=new UserWnd();
userwnd.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(null,"密码错误!!");
System.exit(0);
}
}catch(Exception e)
{}// TODO add your handling code here:
}
}
这是确认按钮部分的代码
代码如下
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==okButton)
{
Name=name.getText();
Pwd=pwd.getText();
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/user?user=root&password=900511";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
String sql = "select * from users where name='" + Name+ "' and pwd = '" + Pwd + "'";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
{
JFrame main = Lib20App.getApplication().getMainFrame();
main.dispose();
UserWnd userwnd=new UserWnd();
userwnd.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(null,"密码错误!!");
System.exit(0);
}
}catch(Exception e)
{}// TODO add your handling code here:
}
}
这是确认按钮部分的代码
catch(Exception e)
{}// TODO add your handling code here:
啥也没做,改成catch(Exception e){e.printStackTrace();}试试
不要写这样的代码。
你可以这么写:
catch(Exception e){
e.printStackTrace(System.err);
}
你把jdbc驱动包包含进来没