我正在Java创建一个管理系统。
我有这个登录表。与数据库的连接看起来很好,因为它没有给出错误。
但是当我尝试执行try{}和catch{}时,它给出了一个错误。
我希望有谁能帮助我。
它总是给出:
catch(Exception ex){JoptionPane.ShowMessageDialog(null,“登录操作错误”,“登录错误”,JoptionPane.Error_Message);}
public class Login extends javax.swing.JFrame {
private Connection con;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
public Login() {
super("System Login");
initComponents();
this.setResizable(false);
this.setLocation((screen.width - 500) / 2, ((screen.height - 350) / 2));
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
comcateg.addItem("Manager");
comcateg.addItem("Clerk");
ButtonListener listener = new ButtonListener();
btlogin.addActionListener(listener);
btcancel.addActionListener(listener);
con = DBConnection.getDBConnection();
if (con == null) {
JOptionPane.showMessageDialog(null, "Error on establishing database connection", "Error", JOptionPane.ERROR_MESSAGE);
this.dispose();
}
}
public void log(){
String user = txtuser.getText();
String pw = txtpw.getText();
String cat = comcateg.getSelectedItem().toString();
String SQL;
SQL = "SELECT * FROM AAP.USERS WHERE user_id='" + user + "' AND pword='" + pw +"' AND categ='" + cat +"'";
**try{
Statement stmt = con.createStatement();
stmt.execute(SQL);
ResultSet rs = stmt.getResultSet();
boolean recordfound = rs.next();
if (recordfound) {
LoadMainWindow();
this.dispose();
} else {
JOptionPane.showMessageDialog(null, "The system could not log you in.\n" +
" Please make sure your username and password are correct", "Login Failure", JOptionPane.INFORMATION_MESSAGE);
txtuser.setText("");
txtpw.setText("");
txtuser.requestFocus();
}
}
catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Error on login operation", "Login Error", JOptionPane.ERROR_MESSAGE);
}
}**
public void LoadMainWindow() {
if (comcateg.getSelectedItem().equals("Manager")) {
new MainWindow().LoginManager();
} else {
new MainWindow().LoginClerk();
}
}
private class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btlogin) {
if (txtuser.getText() == null || txtuser.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Enter username", "Missing field", JOptionPane.DEFAULT_OPTION);
txtuser.requestFocus();
return;
}
if (txtpw.getText() == null || txtpw.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Enter password", "Missing field", JOptionPane.DEFAULT_OPTION);
txtpw.requestFocus();
return;
}
log();
} else if (e.getSource() == btcancel) {
System.exit(0);
}//if else closed
}//actionPerformed() closed
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
userid = new javax.swing.JLabel();
pword = new javax.swing.JLabel();
categ = new javax.swing.JLabel();
txtuser = new javax.swing.JTextField();
txtpw = new javax.swing.JTextField();
comcateg = new javax.swing.JComboBox();
btlogin = new javax.swing.JButton();
btcancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
userid.setText("User ID:");
pword.setText("Password:");
categ.setText("Category:");
txtuser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtuserActionPerformed(evt);
}
});
txtpw.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtpwActionPerformed(evt);
}
});
comcateg.setModel(new javax.swing.DefaultComboBoxModel(new String[] {}));
comcateg.setToolTipText("");
comcateg.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comcategActionPerformed(evt);
}
});
btlogin.setText("Login");
btlogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btloginActionPerformed(evt);
}
});
btcancel.setText("Cancel");
btcancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btcancelActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(40, 40, 40)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jPanel1Layout.createSequentialGroup()
.add(btlogin)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(btcancel))
.add(jPanel1Layout.createSequentialGroup()
.add(categ)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(comcateg, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(jPanel1Layout.createSequentialGroup()
.add(pword)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(txtpw))
.add(jPanel1Layout.createSequentialGroup()
.add(userid)
.add(18, 18, 18)
.add(txtuser, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(64, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(48, 48, 48)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(userid)
.add(txtuser, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(pword)
.add(txtpw, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(categ)
.add(comcateg, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(18, 18, 18)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(btlogin)
.add(btcancel))
.addContainerGap(48, Short.MAX_VALUE))
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void txtuserActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txtpwActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btloginActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btcancelActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void comcategActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btcancel;
private javax.swing.JButton btlogin;
private javax.swing.JLabel categ;
private javax.swing.JComboBox comcateg;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel pword;
private javax.swing.JTextField txtpw;
private javax.swing.JTextField txtuser;
private javax.swing.JLabel userid;
// End of variables declaration
}
DBConnect类代码:
公共类DBConnection{
public static Connection getDBConnection() {
Connection connection;
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
connection = DriverManager.getConnection("jdbc:derby:Ambulance;create=true");
return connection;
} catch (Exception ex) {
return null;
}
}
}
我得到的例外是:
运行:java.sql.sqlsyntaxerrorexception:org.apache.derby.impl.jdbc.sqlexception(未知源)org.apache.derby.impl.jdbc.jdbc.util.generatecssqlexception(未知源)org.apache.derby.impl.jdbc.transactionresourceimpl.wrapinsqlexception(未知源)org.apache.derby.impl.jdbc.transactionresourceimpl.handleexception(未知源)model.java:402)在javax.swing.defaultbuttonmodel.setpressed(Defaultbuttonmodel.java:259)在javax.swing.plaf.basic.basicbuttonlistener.mousereleased(basicbuttonlistener.java:252)在java.awt.component.processMouseEvent(component.java:6505)在javax.swing.jcomponent.processMouseEvent(component.java:3321)在VentQueue.DispatchEventImpl(EventQueue.java:729)在java.awt.EventQueue.Access$200(EventQueue.java:103)在java.awt.EventQueue$3上运行(EventQueue.java:688)在java.awt.EventQueue$3上运行(EventQueue.java:686)在java.security.AccessController.DoPriviled(本机方法)在java.security.ProtectionDomain$1上运行(ava.awt.EventDispatchThread.PumpEvents(EventDispatchThread.java:146)位于java.awt.EventDispatchThread.PumpEvents(EventDispatchThread.java:138)位于java.awt.EventDispatchThread.Run(EventDispatchThread.java:91)
在
SQL = "SELECT * FROM AAP.USERS WHERE user_id='" + user + "' AND pword='" + pw
+"' AND categ='" + cat +"'";
您的AAP
表不存在,您需要确保在查询它之前已经创建了它。
我认为查询没有正确执行,因为模式AAP不存在,并且您正在访问表users“select*FROM AAP.users...”,并且它在第41行stmt.execute(SQL)处出现异常;
因此它将进入catch块。
首先,我想让你知道,我是新来的Symfony。我在路上把我的PHP项目从我自己的“基本”MVC转到SimfOn.该项目已经运行良好,但我在适应Symfony时遇到了一些问题。 我从基本的框架开始,make: user和make: auth。模板运行良好。但是我未能将登录过程转换为AJAX和JSON。 我遵循了这个官方教程:https://symfonycasts.com/screencast/ap
我得到了一个登录表单,提交后,但似乎不自动认证,我可以看到匿名在分析器,即使我登录为管理员。 我正在从数据库中获取数据: 当然,数据库中存储的密码是加密的。 security.yml(app/config/security.yml) SecurityController.php(src/AppBundle/Controller) User.php(src/AppBundle/Entity/User
我使用openAm 9.5.4作为服务提供商,salesforce作为IDP。使用现有java 1.6版本的OpenAm,我的IDP启动了sso工作。但是,当我们将openAm的java版本迁移到1.7时,sso失败,错误为“HTTP状态500-单点登录失败”。java版本更改可能会导致什么问题? 我想确认的一个更重要的问题是,OpenAm 9.5.4是否在Java1.7上支持SSO?有人尝试过这
我是拉威尔的新手,刚刚开始构建我的第一个应用程序。我使用的是Laravel5.2。5.我正在跟踪laracast视频以实现身份验证。当我第一次启动应用程序时,我可以访问/auth/register、/auth/login和/auth/logout。注册和登录工作正常。Register在我的用户表中创建一个条目,/auth/login允许我使用该用户登录。成功登录后,我尝试注销。当我尝试访问/aut
我有一个登记表,它可以注册和登录用户。我使用
我尝试使用spring security进行登录,但它不起作用,因为它返回给我这个链接:http://localhost:8080/login?error并在主页上报告我:这是代码: 静态页面中的一个索引,它重新链接我: 在模板中,我有以下内容: 并且捕获它的请求映射就在那里: 日志:在6.958秒内启动了ProgettoSiwApplication(JVM运行7.964)2018-06-21 1