JDBC ilikequery encounter some problems
От | Jian He |
---|---|
Тема | JDBC ilikequery encounter some problems |
Дата | |
Msg-id | CAMV54g2ONJv=+8VwL-ZD=NVNzSFzcTBAPcKQzCOXRAQshyyDCA@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: JDBC ilikequery encounter some problems
|
Список | pgsql-jdbc |
https://jdbc.postgresql.org/documentation/head/query.html only a few examples. But I encounter some problems when I using ilike operator. I asked this question on Stackoverflow (https://stackoverflow.com/questions/68061908/jdbc-ilike-query-java) Now I also type in here> Hope you guys can help me. I do googled, seems don't have much good post about it.
_______
JDBC successfully connected to PostgreSQL. But some ilike query still have problems. only 1 code is working. I want the first and the third one to working properly.
--------------- not working
String ilikequery = "SELECT * FROM emp where ? iLIKE '%C%' "; PreparedStatement ilikestatement = Main.connection.prepareStatement(ilikequery); ilikestatement.setString(1,"name"); ResultSet resultSet = ilikestatement.executeQuery();
-------------- this one working,
String queryname = "Cowen"; String query = "select * from emp where name = ?"; PreparedStatement statement = Main.connection.prepareStatement(query); statement.setString(1,queryname); ResultSet resultSet = statement.executeQuery();
------------this one not working.
String ilikequerywithparameter = "SELECT * FROM emp" + " where name iLIKE '%"+"?"+"%' "; PreparedStatement ilikestatementpara = Main.connection.prepareStatement(ilikequerywithparameter); ilikestatementpara.setString(1,"c"); ResultSet resultSet = ilikestatementpara.executeQuery();
The last code snippet have Exception error.Exception in thread "main" org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns:
-------- this one is working.
String simpleilikequery = "SELECT * FROM emp" + " WHERE name iLIKE '%C%'";
PreparedStatement simpleilikestatement = Main.connection.prepareStatement(simpleilikequery);
ResultSet resultSet = simpleilikestatement.executeQuery();
В списке pgsql-jdbc по дате отправления: