Advertisement
Nocx

connexion base de données

May 1st, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. private String url = "jdbc:mysql://url/base_de_donnée";
  2.     private String user = "Nom_d'utilisateur";
  3.     private String password = "mot_de_passe";
  4.     public Connection conn;
  5.     public ResultSet result;
  6.     public Statement state;
  7.  
  8.     public void connect()
  9.     {
  10.         try
  11.         {
  12.             Class.forName("com.mysql.jdbc.Driver");
  13.         }
  14.         catch (ClassNotFoundException e1)
  15.         {
  16.             e1.printStackTrace();
  17.         }
  18.         try
  19.         {
  20.             this.conn = DriverManager.getConnection(url, user, password);
  21.             System.out.println("Connexion établie!");
  22.         }
  23.         catch (SQLException e)
  24.         {
  25.             e.printStackTrace();
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement