0
我想从RandevufiltreSorgu.java
得到doktor [0],doktor [1],secilenBolum。我在randevusec中创建了RandevufiltreSorgu
类的对象。但是当我运行查询时,我无法获得我想要的值。没有使用继承。我能做什么?从另一个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的类型是什么?它是一个字符串吗? –
你应该查看一个JDBC教程,该教程描述了如何使用准备好的语句等来正确地执行此操作。一般来说,将JDBC资源(如结果集或语句)声明为类中的字段或在方法之间传递它们是不好的做法,因为它们应该具有最小范围(您想尽快关闭/释放它们)。取决于你的JDBC驱动程序的实现,因为你总是调用'conn.close();'方法结束时,结果集也可能会被关闭。而不是返回结果集,遍历它并返回一个POJO集合。 –