Guest User

Untitled

a guest
Jan 4th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. public class CreateConnectionWithDatabase {
  2.  
  3. public CreateConnectionWithDatabase(){
  4.  
  5. }
  6.  
  7. public Connection createConnection(String user, String password, String database, String server) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {
  8.  
  9. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); //politica de connexion
  10.  
  11. StrictMode.setThreadPolicy(policy);
  12.  
  13. Connection connection = null;
  14.  
  15. String connectionUrl = null;
  16.  
  17. Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  18.  
  19. connectionUrl = "jdbc:mysql://"+server+"/"+database;
  20.  
  21. connection = DriverManager.getConnection (connectionUrl, user, password);
  22.  
  23. return connection;
  24.  
  25. }
  26.  
  27.  
  28.  
  29. }
  30.  
  31. createConnectionWithDatabase = new CreateConnectionWithDatabase();
  32. connection = createConnectionWithDatabase.createConnection("jxxxu@lxxza-sxxxer","12xxxa", "gym_cachi","xxxxx-server.xxxx.xxxxx.azure.com:3306");
Add Comment
Please, Sign In to add comment