Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dbConnection;
- import java.sql.*;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import org.example.www.serviciopractica1.GenerarPresupuesto;
- public class DBConnect {
- private Connection con;
- private Statement st;
- private ResultSet result;
- public ResultSet getResult() {
- return result;
- }
- public DBConnect() {
- String url = "jdbc:mysql://localhost:3306/mtis";
- String user = "root";
- String password = "";
- try{
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(url, user, password);
- st = con.createStatement();
- } catch(Exception e) {
- System.out.println("Error: " + e);
- }
- }
- public void getCodigoPostal(String cp) {
- try {
- String query = "select * from codigospostales where codigoPostal='" + cp + "';";
- result = st.executeQuery(query);
- } catch(Exception e) {
- System.out.println("Error: " + e);
- }
- }
- public boolean checkSoapKey(String soapKey) throws SQLException{
- boolean valido = false;
- try {
- String query = "select * from soapkey where soapKey='" + soapKey + "';";
- result = st.executeQuery(query);
- } catch(Exception e) {
- System.out.println("Error: " + e);
- }
- if(result.next())
- valido = true;
- return valido;
- }
- public boolean savePresupuesto(GenerarPresupuesto presupuesto) throws SQLException {
- boolean valido = true;
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
- String fecha = df.format(presupuesto.getInfoInicial().getFechaPresupuesto());
- try {
- String query = "insert into presupuestos (fechaPresupuesto, idCliente, referenciaProducto, cantidadProducto)"
- + " values ('" + fecha + "', "
- + presupuesto.getInfoInicial().getIdCliente() + ", '" + presupuesto.getInfoInicial().getReferenciaProducto() + "', "
- + presupuesto.getInfoInicial().getCantidadProducto() + ");";
- st.executeUpdate(query);
- } catch(Exception e) {
- System.out.println("Error: " + e);
- valido = false;
- }
- return valido;
- }
- public void getPresupuestos() {
- try {
- String query = "select * from presupuestos;";
- result = st.executeQuery(query);
- } catch(Exception e) {
- System.out.println("Error: " + e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement