sql query via jdbc [duplicate]
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 ("?", "?")";
精彩评论