Guest User

Untitled

a guest
Feb 15th, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. package org.example.www.practica1wsdlfile;
  2.  
  3. import java.sql.*;
  4. import java.text.DateFormat;
  5. import java.text.SimpleDateFormat;
  6.  
  7. public class DBConnect {
  8. private Connection con;
  9. private Statement st;
  10. private ResultSet result;
  11.  
  12. public ResultSet getResult() {
  13. return result;
  14. }
  15.  
  16. public DBConnect() {
  17. String url = "jdbc:mysql://localhost:3306/mtis";
  18. String user = "root";
  19. String password = "";
  20.  
  21. try{
  22. Class.forName("com.mysql.jdbc.Driver");
  23.  
  24. con = DriverManager.getConnection(url, user, password);
  25. st = con.createStatement();
  26. } catch(Exception e) {
  27. System.out.println("Error: " + e);
  28. }
  29. }
  30.  
  31. public void getCodigoPostal(String cp) {
  32. try {
  33. String query = "select * from codigospostales where codigoPostal='" + cp + "';";
  34. result = st.executeQuery(query);
  35. } catch(Exception e) {
  36. System.out.println("Error: " + e);
  37. }
  38. }
  39.  
  40. public boolean checkSoapKey(String soapKey) throws SQLException{
  41. boolean valido = false;
  42.  
  43. try {
  44. String query = "select * from soapkey where soapKey='" + soapKey + "';";
  45. result = st.executeQuery(query);
  46. } catch(Exception e) {
  47. System.out.println("Error: " + e);
  48. }
  49.  
  50. if(result.next())
  51. valido = true;
  52.  
  53. return valido;
  54. }
  55.  
  56. public boolean savePresupuesto(GenerarPresupuesto presupuesto) throws SQLException {
  57. boolean valido = true;
  58. DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  59.  
  60. String fecha = df.format(presupuesto.getFechaPresupuesto());
  61.  
  62. try {
  63. String query = "insert into presupuestos (fechaPresupuesto, idCliente, referenciaProducto, cantidadProducto)"
  64. + " values ('" + fecha + "', "
  65. + presupuesto.getIdCliente() + ", '" + presupuesto.getReferenciaProducto() + "', "
  66. + presupuesto.getCantidadProducto() + ");";
  67. st.executeUpdate(query);
  68. } catch(Exception e) {
  69. System.out.println("Error: " + e);
  70. valido = false;
  71. }
  72.  
  73. return valido;
  74. }
  75.  
  76. public void getPresupuestos() {
  77. try {
  78. String query = "select * from presupuestos;";
  79. result = st.executeQuery(query);
  80. } catch(Exception e) {
  81. System.out.println("Error: " + e);
  82. }
  83. }
  84. }
Add Comment
Please, Sign In to add comment