Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. package fr.destinycore.faction.manager;
  2.  
  3.  
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9.  
  10. public class SqlConnection {
  11.  
  12. private Connection connection;
  13. private String urlbase,host,database,user,password;
  14.  
  15. public SqlConnection(String urlbase, String host, String database, String user, String password) {
  16. this.urlbase = urlbase;
  17. this.host = host;
  18. this.database = database;
  19. this.user = user;
  20. this.password = password;
  21. }
  22.  
  23. public void connection(){
  24. if(!isConnected()){
  25. try {
  26. connection = DriverManager.getConnection(urlbase + host + "/" + database, user, password);
  27. System.out.println("connected ok");
  28. } catch (SQLException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32. }
  33.  
  34. public void disconnect(){
  35. if(isConnected()){
  36. try {
  37. connection.close();
  38. System.out.println("connected off");
  39. } catch (SQLException e) {
  40. e.printStackTrace();
  41. }
  42. }
  43. }
  44.  
  45. public boolean isConnected(){
  46. return connection != null;
  47. }
  48.  
  49. public int getAnimateur(){
  50.  
  51. int animateur = 0;
  52.  
  53. try{
  54. PreparedStatement q = connection.prepareStatement("SELECT animateur FROM staff");
  55.  
  56. ResultSet resultat = q.executeQuery();
  57. animateur = resultat.getInt("animateur");
  58. System.out.println(resultat.getInt("animateur")+"");
  59. q.close();
  60. } catch (SQLException e){
  61. e.printStackTrace();
  62. }
  63. return animateur;
  64.  
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement