3 가지 키 값으로 더비 데이터베이스를 검색 할 수 있어야합니다. GUI가 설정되어 있고 데이터베이스의 데이터로 채울 수 있습니다. 어느 방향 으로든 스크롤 할 수 있도록 설정했습니다. 내가 가진 문제는 내 쿼리가 실패한 키 필드 중 하나의 특정 검색을 수행하는 방법을 만들 때입니다. 다음은 검색을 용이하게하기 위해 사용하려는 방법입니다. 문을 사용하고 변수를 String 문에 연결하려고 시도했으며 준비된 문을 사용하고 변수를 바인딩 해 보았습니다. 어느 쪽도 일을 할 수 없습니다. 오류가 발생한 코드에 표시했습니다.
public static void Search(){
String idField = InitGUI.getidField().getText();
String sql = ("SELECT * FROM MYDB.Employee WHERE Employee ID = '"+idField +"'");
try {
// prepStat = dbCon.prepareStatement(sql);
// prepStat.setString(1, idField);
// rs = prepStat.executeQuery();
rs = stmt.executeQuery(sql); <== This is where the error occurs.
SqlStatements.SearchResult(rs.getRow());
} catch (SQLException e) {
e.printStackTrace();
}
}
다음은 스택 트레이스입니다.
Connected to database
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "ID" at line 1, column 44.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown Source)
at Scheduler.DBConnector.Search(DBConnector.java:77)
at Scheduler.myActionListener.actionPerformed(myActionListener.java:20)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.sql.SQLException: Syntax error: Encountered "ID" at line 1, column 44.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 46 more
Caused by: ERROR 42X01: Syntax error: Encountered "ID" at line 1, column 44.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 40 more
과 .
사이 를 잊으 셨습니까?Employee
ID
"SELECT * FROM MYDB.Employee WHERE Employee.ID = "+idField
stacktrace Syntax error
는 SQL 구문이 잘못되었음을 의미합니다. Encoutered "ID" at line 1
수단 syntaxic 분석 사이에 실패 Employee
하고 ID
.
열 이름 Employee ID
인 경우 DBMS에 따라 큰 따옴표 또는 역 따옴표로 이스케이프하십시오.)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다