sql中的数据库问题 [英] database questions in sql
本文介绍了sql中的数据库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下查询在SQL中:
SELECT r.reservation_no, f.flight_no, r.departure_date,
f.departure_time, f.duration
FROM flights f, reservations r
WHERE f.flight_no=r.flight_no AND r.customer_ssn="234567";
以表格形式将结果打印到屏幕上.
Print the results to the screen in table form.
我需要使它与JDBC兼容.
I need to make it in such a way that it can be compatible with JDBC.
rs = stmt.executeQuery("SELECT r.reservation_no, f.flight_no, r.departure_date, f.departure_time, f.duration FROM flights f, reservations r WHERE f.flight_no=r.flight_no AND r.customer_ssn="234567");
while ( rs.next() ) {
**String capacity = rs.getString("??????"); -- what should I use here? as I have to take many values from the tables?**
System.out.println(capacity);
}
推荐答案
String query = "SELECT r.reservation_no, f.flight_no, r.departure_date, f.departure_time, f.duration FROM flights f, reservations r WHERE f.flight_no=r.flight_no AND r.customer_ssn="?" ";
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, customer_ssn);
result = ps.executeQuery();
这篇关于sql中的数据库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文