Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. package com.balgass.tp1.database;
  2.  
  3. import java.sql.*;
  4.  
  5.  
  6. public class DataBase {
  7.  
  8. Connection conn;
  9.  
  10. public DataBase() throws SQLException, ClassNotFoundException {
  11. String url = "jdbc:mysql://localhost:3306/basesita";
  12. Class.forName("com.mysql.cj.jdbc.Driver");
  13. conn = DriverManager.getConnection(url,"root","windowsde9");
  14. }
  15.  
  16. public void close() throws SQLException{
  17. conn.close();
  18. }
  19.  
  20. public ResultSet query(String sql) throws SQLException{
  21. Statement stmt = conn.createStatement();
  22. ResultSet rs;
  23.  
  24. rs = stmt.executeQuery(sql);
  25. return rs;
  26. }
  27.  
  28. public void execute (String query, int id) throws SQLException{
  29. PreparedStatement preparedStmt = conn.prepareStatement(query);
  30. preparedStmt.setInt(1, id);
  31. preparedStmt.execute();
  32. }
  33.  
  34. public Connection getConnection(){
  35. return conn;
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement