Guest User

Untitled

a guest
Jun 12th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. Consulta="UPDATE producto SET descripcion = '"+descripcion+"' WHERE id ="+id;
  2.  
  3. Consulta="UPDATE producto SET descripcion = "+descripcion+" WHERE id ="+id;
  4.  
  5. public boolean Modificar(String descripcion ,int id){
  6. if (!conexion.estaconectado()){
  7. conexion.conectar();
  8. }
  9. String Consulta="";
  10. Consulta="UPDATE producto SET descripcion = '"+descripcion+"' WHERE id ="+id;
  11.  
  12. int r=conexion.EnviarActualizacion(Consulta);
  13. if (r!=0){
  14. return true;
  15. }
  16. else{
  17. return false;
  18. }
  19. }
  20.  
  21.  
  22. public class conexion {
  23. public static Connection cnx = null;
  24. public static String msg ="";
  25.  
  26. public static String conectar(){
  27.  
  28. try{
  29. /*pro.agrega(entipro);*/
  30. Class.forName("oracle.jdbc.OracleDriver");
  31. cnx= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","SYSTEM","system");
  32. msg="conectado";
  33. }
  34. catch(SQLException e){
  35. msg = e.getMessage();
  36. }
  37. catch(ClassNotFoundException e){
  38. msg = e.getMessage();
  39. }
  40. return msg;
  41. }
  42.  
  43. public static boolean estaconectado(){
  44.  
  45. if (cnx!=null){
  46. return true;
  47. }
  48. else{
  49. return false;
  50. }
  51. }
  52.  
  53. public static int EnviarActualizacion(String cons){
  54. try {
  55. return ejecutarActualizacion(cnx.prepareStatement(cons));
  56. }
  57. catch (SQLException e){
  58. msg="Error al actualizar tabla : " + e.getMessage();
  59. }
  60. return 0;
  61. }
  62.  
  63.  
  64. public static int ejecutarActualizacion(PreparedStatement sp){
  65.  
  66. try{
  67. return sp.executeUpdate();
  68. }catch(SQLException e){
  69. msg ="eror al actualizar la tabla"+ e.getMessage();
  70. }
  71. return 0;
  72. }
  73.  
  74. String des = request.getParameter("descripcion");
  75. int codigo = Integer.parseInt(request.getParameter("codigo"));
  76. lnegocio ln = new lnegocio();
  77. boolean estado = ln.modificar(des, codigo);
  78. out.println(estado);
Add Comment
Please, Sign In to add comment