Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.balgass.tp1.database;
- import java.sql.*;
- public class DataBase {
- Connection conn;
- public DataBase() throws SQLException, ClassNotFoundException {
- String url = "jdbc:mysql://localhost:3306/basesita";
- Class.forName("com.mysql.cj.jdbc.Driver");
- conn = DriverManager.getConnection(url,"root","windowsde9");
- }
- public void close() throws SQLException{
- conn.close();
- }
- public ResultSet query(String sql) throws SQLException{
- Statement stmt = conn.createStatement();
- ResultSet rs;
- rs = stmt.executeQuery(sql);
- return rs;
- }
- public void execute (String query, int id) throws SQLException{
- PreparedStatement preparedStmt = conn.prepareStatement(query);
- preparedStmt.setInt(1, id);
- preparedStmt.execute();
- }
- public Connection getConnection(){
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement