Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bdd;
- import java.sql.*;
- import java.util.ArrayList;
- public class BaseDeDonnees {
- /**
- * URL de connection
- */
- private final static String URL = "jdbc:mysql://localhost:3306/projet_bdd?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
- /**
- * Nom du user
- */
- private final static String LOGIN = "root";
- /**
- * Mot de passe du user
- */
- private final static String PASSWORD = "";
- public Connection getConnection() throws SQLException {
- return DriverManager.getConnection(URL, LOGIN, PASSWORD);
- }
- public void executerRequete(String req) {
- Connection con = null;
- Statement stmt = null;
- try {
- con = getConnection();
- stmt = con.createStatement();
- final ResultSet rset = stmt.executeQuery(req);
- while (rset.next()) {
- int n = rset.getMetaData().getColumnCount();
- for(int i = 1; i <= n; i++)
- System.out.print(rset.getString(i) + " ");
- System.out.print('\n');
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (stmt != null) {
- try {
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement