SEVERE: 空错误 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

huangapple 未分类评论63阅读模式
英文:

SEVERE: null error com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

问题

以下是翻译后的内容:

我在关于“SEVERE”错误的问题上反复出现错误,我尝试更改请求的语法,但是即使更改后,我仍然会遇到错误,并且它们的请求似乎是错误的。你有解决方案吗?

这是我的错误:

2020年5月29日 下午4:26:02 javaapplicationhotel2.Login_Form jButton_LoginActionPerformed
SEVERE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 在你的SQL语法中存在一个错误;请查阅适用于你的MariaDB服务器版本的手册,以获取关于正确使用语法的说明,附近的内容为“'users' WHERE 'username' = 'nom d'utilisateur' AND 'password' = ''”(位于第1行)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	...

这是我的代码,用于打开登录页面,通过点击登录按钮而不输入任何内容,应该显示代码中的错误消息,但实际上我得到了上面的错误。

PreparedStatement st;
ResultSet rs;
    
// 获取用户名和密码
String username = jTextField_Username.getText();
String password = String.valueOf(jPasswordField.getPassword());
    
// 查询语句,用于检查是否存在相应的用户名和密码
String query = "SELECT * FROM 'users' WHERE 'username' = ? AND 'password' = ?";
    
try {
    st = (PreparedStatement) Connecter.getConnection().prepareStatement(query);
        
    st.setString(1, username);
    st.setString(2, password);
    rs = st.executeQuery();
        
    if(rs.next())
    {
        // 打开管理页面
        Gestionnaire form = new Gestionnaire();
        form.setVisible(true);
        form.pack();
        form.setLocationRelativeTo(null);
            
        this.dispose();
            
    }else{
        // 错误提示
        JOptionPane.showMessageDialog(null, "Invalid username/password", "Authentication Error", 2);
    }
        
} catch (SQLException ex) {
    java.util.logging.Logger.getLogger(Login_Form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

注意:这里的代码片段中可能存在错误,因为我只是翻译了你提供的代码。如果出现问题,你需要仔细检查代码逻辑和语法。

英文:

I have a recurring error vis-à-vis my "SEVERE", I ask myself to change the syntax of my request but even by changing I always have an error and their requests seem false. Do you have a solution

here my error:

mai 29, 2020 4:26:02 PM javaapplicationhotel2.Login_Form jButton_LoginActionPerformed
SEVERE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''users' WHERE 'username' = 'nom d\'utilisateur' AND 'password' = ''' at line 1
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.Util.getInstance(Util.java:386)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)
	at javaapplicationhotel2.Login_Form.jButton_LoginActionPerformed(Login_Form.java:428)
	at javaapplicationhotel2.Login_Form$8.actionPerformed(Login_Form.java:204)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
	at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:297)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
	at java.desktop/java.awt.Component.processEvent(Component.java:6401)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2762)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

here my code here my code which is used to open a login page, by clicking on loggin without writing anything, this should display the error message present in my code, but instead I have this error above

   PreparedStatement st;
    ResultSet rs;
    
    // donnez l'username et le password 
    String username = jTextField_Username.getText();
    String password = String.valueOf(jPasswordField.getPassword());
    
    // requete indiquant si les identifiants existent 
    String query = "SELECT * FROM 'users' WHERE 'username' = ? AND 'password' = ?";
    
  
    try {
        st = (PreparedStatement) Connecter.getConnection().prepareStatement(query);
        
        st.setString(1, username);
        st.setString(2, password);
        rs = st.executeQuery();
        
        if(rs.next())
        {
            //ouvrir le gestionnaire 
            Gestionnaire form = new Gestionnaire();
            form.setVisible(true);
            form.pack();
            form.setLocationRelativeTo(null);
            
            this.dispose();
            
        }else{
            //erreur  
            JOptionPane.showMessageDialog(null, " Nom de compte / mot de passe invalide", "Erreur d'authentification",2);
        }
        
    } catch (SQLException ex) {
        java.util.logging.Logger.getLogger(Login_Form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }

huangapple
  • 本文由 发表于 2020年5月29日 22:35:41
  • 转载请务必保留本文链接:https://java.coder-hub.com/62088400.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定