반응형
구문에 문제가 있음을 보여주는 SQLException으로 예외가 발생하고 설명서에서 동일하게 확인하십시오.
내 자바 코드는 다음과 같습니다.
PreparedStatement pst;
String sql ="SELECT * FROM patient.medicine where _id=?";
pst = cn.prepareStatement(sql);
pst.setInt(1, 1);
ResultSet rs = pst.executeQuery(sql);
id 값을 보유한 변수를 추가하여 실행하면 모든 것이 잘 작동합니다.
*SELECT * FROM patient.medicine where _name=?*
Oct 19, 2013 11:15:46 AM com.seed.entity.Patient getData
SEVERE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near '?' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
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:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2728)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2678)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1612)
at com.seed.entity.Patient.getData(Patient.java:257)
at com.seed.entity.Patient.main(Patient.java:360)
해결 방법
코드에 오류가 하나 있습니다.
PreparedStatement pst;
String sql ="SELECT * FROM patient.patient P WHERE P._ID = ?";
pst = cn.prepareStatement(sql);
pst.setInt(1, 1);
ResultSet rs = pst.executeQuery(); // without arguments
참조 페이지 https://stackoverflow.com/questions/19462563
반응형
'MySql' 카테고리의 다른 글
MySQL 1부터 시작하지 않는 자동 증가 (0) | 2020.12.20 |
---|---|
MySQL Snow Leopard에 mysql gem 설치 문제 : 초기화되지 않은 상수 MysqlCompat :: MysqlRes (0) | 2020.12.20 |
MySQL SELECT DISTINCT는 대소 문자를 구분해야합니까? (0) | 2020.12.20 |
MySQL GPS 좌표를 위해 데이터베이스에 몇 개의 유효 숫자를 저장해야합니까? (0) | 2020.12.20 |
MySQL Mac에서 Laravel 설정 php artisan migrate error : No such file or directory (0) | 2020.12.20 |
댓글