0
doktor [0], doktor [1], secilenBolum을 RandevufiltreSorgu.java
에서 가져오고 싶습니다. 난 RandevufiltreSorgu
클래스의 객체를 randevusec에 만들었습니다. 그러나 쿼리를 실행하면 원하는 값을 얻을 수 없습니다. 사용중인 상속은 없습니다. 내가 무엇을 할 수 있을지?다른 Java 클래스에서 값 가져 오기
public class randevusec {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
public ResultSet saatler() throws SQLException, Exception {
randevufiltreSorgu nesne = new randevufiltreSorgu();
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/tipmerkezivt", "postgres", "2569");
ps = conn.prepareStatement(
"WITH Q1 AS(\n" + " select * from doktor natural join bolum where dr_adi='" + nesne.doktor[0]
+ "' and dr_soyadi='" + nesne.doktor[1] + "' and bolum.b_adi='" + nesne.secilenBolum + "'\n"
+ " )\n" + " select cs_saat from doktorun_programi natural join Q1\n" + " ",
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = ps.executeQuery();
return rs;
} catch (Exception e) {
throw new Exception("Bağlantı başarısız!");
}
finally {
conn.close();
}
}
}
doktor의 종류는 무엇입니까? 문자열입니까? –
Prepared Statement로 올바르게 수행하는 방법을 설명하는 JDBC 자습서를 찾아보아야합니다. 일반적으로 결과 집합이나 문과 같은 JDBC 리소스를 클래스의 필드로 선언하거나 메소드간에 전달하는 것은 좋지 않습니다. 최소한의 범위 (가능한 한 빨리 닫고 해제하려는 경우). JDBC 드라이버 구현에 따라, 메소드 끝에서 항상'conn.close();를 호출하기 때문에 결과 세트가 닫힐 수도 있습니다. 결과 집합을 반환하는 대신 결과 집합을 반복하고 POJO 컬렉션을 반환합니다. –