我有查詢從MySQLJAVA - MySQL的一個ArrayList
String sqlSearch = "SELECT * from Item"
和方法與ArrayList的
public static ArrayList<String> checkNo() throws SQLException {
ArrayList<String> no= new ArrayList<String>();
DbManager db = new DbManager();
db.connect();
String sql = "SELECT * from Category where id = " + idUser + " ";
Statement stmt = db.connect().createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
no.add(rs.getString("nameCategory"));
}
db.disconnect();
return no;
}
我從特定的用戶在ArrayList中得到他的範疇,但如何將這些類別sqlSearch傳遞???
SELECT * from Item where category ????
data from ArrayList
任何想法?
建議使用預準備語句。 http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html – dsharew