メインプロジェクトクラスでこのメソッドを呼び出し、パラメータなどを入力すると、エラーが発生します。テーブルのフィールドはID
と表示されており、ユーザフィールドからのユーザ入力をSQLテーブルのID
フィールドと比較しています。ユーザーからの入力がID
フィールドとPASSWORD
フィールドとSQLテーブルから一致する場合、ユーザーはメインGUI画面にユーザーを送信する必要があります。しかし、そうではありません。接続認証の失敗JDBC
エラー:
run: java.sql.SQLSyntaxErrorException: Comparisons between 'INTEGER' and 'CHAR (UCS_BASIC)' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1') at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source) at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source) at org.apache.derby.client.am.Statement.executeQuery(Unknown Source) at GUI.Login_Check.CoLogin(Login_Check.java:27) at GUI.Login.btnSubmitActionPerformed(Login.java:208) at GUI.Login.access$200(Login.java:17) at GUI.Login$3.actionPerformed(Login.java:110) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6525) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6290) at java.awt.Container.processEvent(Container.java:2234) at java.awt.Component.dispatchEventImpl(Component.java:4881) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462) at java.awt.Container.dispatchEventImpl(Container.java:2278) at java.awt.Window.dispatchEventImpl(Window.java:2750) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) Caused by: org.apache.derby.client.am.SqlException: Comparisons between 'INTEGER' and 'CHAR (UCS_BASIC)' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1') at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source) at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source) at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source) at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source) at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source) at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source) at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source) at org.apache.derby.client.am.Statement.flowExecute(Unknown Source) at org.apache.derby.client.am.Statement.executeQueryX(Unknown Source) ... 41 more
コード:
public static void CoLogin(String username, String password){
try{
String dbuser = "";
String dbpass = "";
String url = "jdbc:derby://localhost:1527/Java-App";
String user = username;
String pass = password;
Connection con = DriverManager.getConnection(url, "admin", "admin");
Statement stmt = con.createStatement();
String SQL = "SELECT * FROM MEMBERS WHERE ID='" + user + "' && PASSWORD='" + pass + "'";
ResultSet rs = stmt.executeQuery(SQL);
while(rs.next()){
dbuser= rs.getString("ID");
dbpass = rs.getString("PASSWORD");
}
if(user.equals(dbuser) && pass.equals(dbpass)){
Main x = new Main();
x.setVisible(true);
}
else{
Login x = new Login();
x.setVisible(true);
}
//Connection con = DriverManager.getConnection(url, user, pass);
}
catch(SQLException error){
System.out.println(error.getMessage());
}
エラーの説明「ただし、これはあてはまらない」とはあまりにも曖昧です。問題の根本的な原因を深く知る良い方法は、デバッグです。 'rs.next()'が少なくとも1回は 'true'を返すかどうか確認してください。 'rs.getString(" ID ")'と 'rs.getString(" PASSWORD ")'によって返された値を確認してください。システムエラーログにエラーがないか確認してください。これはあなたの根本的な問題を絞り込み、たとえその原因を理解できない場合でも、結果を元に戻ってくると助けになります。 –
'&&'は動作しますか?私はそれが「AND」であると予想していただろう。また、SQLインジェクションを避けるために、クエリ文字列に直接値をダンプする代わりに、パラメータ化されたクエリを使用する必要があります。 – JonK
@RobertoLinares rs.getStringの値を出力するためにsoutを追加しましたが、同じ接続認証の失敗が返されます。つまり、基本的にはcatchステートメントにまっすぐ進みます。 –