현재 '% input %'와 (과) 일치하는 항목을 "검색"할 때 테이블의 모든 데이터를 반환하는 JDBC 연결을 구현하려고합니다.java jdbc connection - 결과 세트 출력 문제
내가 검색 결과로 결과 집합의 모든 행을 반환하려고 ResultSet rs4 = stm4.executeQuery("select imageTime from image_data where imageName like '%" + value3 + "%' or imageTime like '%" + value3 + "%' or imageLocation like '" + value3 + "'");
예. 하지만 더 이상 행이 없을 때 Resultset.next 명령을 사용하면 은 다음 결과 집합을 모두 null로 만듭니다.
id가 전체 결과 집합을 출력하는 방법을 좋아한다면, 감사.
편집 편집 : 더 직접적으로; 결과 집합의 각 포함 열의 각 행에서 모든 데이터 조각을 가져 오는 방법이 필요합니다. 그래서 나는 그것을 출력 할 수있다. 이것은 아래에서 시도한 것입니다.
rs4 = a 아래에 선언 된 결과 집합.
여기 내 코드입니다.
select imageName,imageLocation,imageTime from .....
이 그 다음을 생성하기 위해이 쿼리를 사용
if(name_time_location == 1)
{
String value3=searchInput.getText();//Sets the search Input as value3
// selecting the cominbation from table, that match input options
try{
con = DriverManager.getConnection("jdbc:mysql:blah blah");
// Query the database for the correct username and passord
Statement stm3 = con.createStatement();
Statement stm4 = con.createStatement();
Statement stm5 = con.createStatement();
//queries database for password from input username
ResultSet rs3 = stm3.executeQuery("select imageName from image_data where imageName like '%" + value3 + "%' or imageTime like '%" + value3 + "%' or imageLocation like '" + value3 + "'");
//ResultSetMetaData rsmd = rs3.getMetaData();
//stm3.setFetchSize(5);
//rs3.last();
//int numberOfRows = rs3.getRow();
//String[] resultList;
//resultList = new String[numberOfRows];
// Fetch each row from the result set
rs3.beforeFirst();
while(rs3.next())
{
imageSearchResult1 = rs3.getString(1);
rs3.next();
imageSearchResult11 = rs4.getString(1);
rs3.next();
imageSearchResult12 = rs4.getString(1);
rs3.next();
imageSearchResult13 = rs4.getString(1);
rs3.next();
imageSearchResult14 = rs4.getString(1);
}rs3.close();
}catch (Exception e)
{
//System.out.println("Exception: " + e + "");
}
System.out.println("Search Results: \nName: " + imageSearchResult1 + " Time stamp: " + imageSearchResult2 + " Location: " + imageSearchResult3 + "\n" +
"Name: " + imageSearchResult11 + " Time stamp: " + imageSearchResult21 + " Location: " + imageSearchResult31 + "\n" +
"Name: " + imageSearchResult12 + " Time stamp: " + imageSearchResult22 + " Location: " + imageSearchResult32 + "\n" +
"Name: " + imageSearchResult13 + " Time stamp: " + imageSearchResult23 + " Location: " + imageSearchResult33 + "\n" +
"Name: " + imageSearchResult14 + " Time stamp: " + imageSearchResult24 + " Location: " + imageSearchResult34 + "\n");
일부 예외가 있습니까? 당신의 문제가 충분히 명확하지 않습니다. – Logan
SQL 쿼리에 문제가있을 수 있습니다. 해당하는 where 절에 레코드가 없음을 의미합니다. –
또한 rs4가 무엇인지 알 수 있도록 질문을 편집 할 수 있습니까? stm5에서만 imagelocation을 선택하기 때문에 rs5.getString (2)를 사용하면 예외가 발생합니다. – Logan