在java中,我使用Prepared语句从数据库中获取值。这里我使用了Index,然后我还绑定了值,我使用了以下查询
Select pname from project where pid="12547";
像这样,我需要从表格项目中提取大约3000个"pname"。执行此操作需要更多的时间。有没有jar可以在java中更快地执行sql查询?
为什么要为这3000个pid执行单独的查询。如果你确信你必须执行那么多查询,你可以切换到最适合你逻辑的任何一个:
select pname from project where pid BETWEEN 1000 and 4000;
select pname from project where pid IN (1000, 1001, ...);
select pname from project where pid > 2000 and pid < 5000;
您可以在where子句中使用这些来修改SQL查询
Operator Description
= Equal
<> Not equal. Note: In some versions of SQL this operator may be written as !=
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN To specify multiple possible values for a column
编辑
如果你的价值观是动态的,那么
String selectSQL = "select pname from project where pid IN(?, ?);";
dbConnection = getDBConnection();
preparedStatement = dbConnection.prepareStatement(selectSQL);
preparedStatement.setInt(1, 2000);
preparedStatement.setInt(2, 5000);
// execute select SQL stetement
ResultSet rs = preparedStatement.executeQuery();