私は、JDBC "Statement"を使用してCRUD操作を実行するコードを用意しています。今、私はすべてのステートメントを "PreparedStatement"に置き換える必要がありますが、私は以下のコードのようにそれを返す/使用する方法について混乱しています。助けてください。ユーティリティクラスからPreparedStatementを返す/使用する
MyDao.java
public class MyDao extends BaseDao{
public MyDao() {
super();
}
public void search(){
ResultSet rs = null;
try {
statement.executeQuery("SELECT * FROM testTable");
rs = statement.getResultSet();
reset();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
BaseDao
public class BaseDao {
Connection connection=null;
Statement statement = null;
public BaseDao() {
try {
Class.forName("org.postgresql.Driver");
connection = (Connection) DriverManager.getConnection("url","user","password");
statement = connection.createStatement();
}
catch (Exception e){
e.printStackTrace();
}
}
public void reset(){
try{
statement.close();
connection.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
質問には一切答えません。 – EJP
私の質問はPreparedStatementに関するものです。上記のコードでStatementが使用される方法でPreparedStatementを使用できますか? – AbhiN