sql中的数据库问题

时间:2010-11-08 08:17:53

标签: sql mysql jdbc

以下查询在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";

以表格形式将结果打印到屏幕上。

我需要以能够与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);
}

2 个答案:

答案 0 :(得分:3)

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();

答案 1 :(得分:0)

如果我已正确理解你的问题,那么取代???您可以拥有列名称或列索引号。