开发者

sql query via jdbc [duplicate]

Thi开发者_StackOverflow社区s question already has answers here: Closed 12 years ago.

Possible Duplicate:

sql query with jdbc

How dow e find the wuery frok mysql.


Your query should be like this:

String query =  "INSERT INTO reservations (flight_no, departure_date) VALUES (?, ?)";

The "?" indicate that you need to provide data for it be inserted into database.


String query =  "INSERT INTO reservations (flight_no, departure_date) VALUES (?, ?)";

PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, flight_no);
ps.setDate(2, departure_date );
result = ps.executeQuery();


In the query you must replace parameters with question marks. Use ? instead of "CSC585" and "2010-05-31". Those question marks will be replaced by values set by .setString() and similar methods.


use setDate instead of setString :

ps.setDate(2, departure_date );

also if you use prepared use question mark in your query like

String query =  "INSERT INTO reservations (flight_no, departure_date) VALUES ("?", "?")";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜