왜 3000pid에 대해 개별 쿼리를 실행하고 있습니까? 당신은 당신이 이들의로 전환 할 수 있습니다 많은 쿼리를 실행하는 본 적이있을 것입니다 경우 가장 그 논리에 맞는 : 당신이 절은 당신의 SQL 쿼리를 수정하는 경우에 이러한 사용할 수 있습니다
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;
을
다음
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();
'pid IN (xx, yy, ...)'프로젝트에서 pname을 (를) 사용 하시겠습니까? –
그런 항아리가 없습니다. 이전 대답에서 제안한 것처럼 쿼리 수를 줄이려고 할 수 있습니다. 어떤 이유로 든 이러한 호출을 순차적으로 수행해야하는 경우 DB를 조정해야합니다 (기본 키가 아닌 경우 pid에 인덱스 추가 등). –
java에서이 명령문을 실행해야하며 준비된 명령문을 사용하여 [IN()] 내부의 값을 바인딩하는 방법도 필요합니다. 값은 ** 동적 **입니다. .. – karthik