Inconvenente con la estructura de programación getPreparedStatement de Jsp
try{
ResultSet rs = DBUtils.getPreparedStatement("select * from News").executeQuery();
while(rs.next()){
News n=new News(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7));
ls.add(n);
}
} catch (ClassNotFoundException | SQLException ex){
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
}
return ls;
}
public static List<News> getNewById(int id){
List<News> ls=new LinkedList<>();
String sql="select * from News where id="+id;
try{
ResultSet rs = DBUtils.getPreparedStatement(sql).executeQuery();
while(rs.next()){
News n=new News(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7));
ls.add(n);
}
} catch (ClassNotFoundException | SQLException ex){
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
}
return ls;
}
public void edit(int id, String title, String description, String detail,String category,String image){
String sql="update news set title=?, description=?,detail=?,category=?,image=?" +" where id=?";
PreparedStatement ps;
try{
ps= DBUtils.getPreparedStatement(sql);
Ps.setString(1, title);
Ps.setString(2, description);
Ps.setString(3, detail);
Ps.setString(4, category);
Ps.setString(5, image);
Ps.setInt(6, id);
ps.executeUpdate();
} catch (ClassNotFoundException | SQLException ex){
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null,ex);
}
}
public void delete(int id){
try{
String sql="delete News where id=?";
PreparedStatement ps= DBUtils.getPreparedStatement(sql);
ps.setInt(1, id);
ps.executeUpdate();
} catch (ClassNotFoundException | SQLException ex){
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null,ex);
}
}
}
Me muestra un error en las líneas de código:
Que dice :
PreparedStatement ps= DBUtils.getPreparedStatement(sql);
La descripción del error es:
Cannot find symbol
Symbol: method getPreparedStatement(String)
Location: variable DBUtils of type Object
Surround with …
Introduce …
----
(Alt – show hints)
Oprimo las teclas (Alt – show hints) y me salen unas instrucciones que empiezan con las ´palabras Surround with y no se cual emplear.
No se a que se deba este error. Ya que veo todo bien definido y codificado.