Guest User

Untitled

a guest
Nov 9th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. class Connection_maker
  2. {
  3. private Connection conn;
  4. private static final String DESTINATION = "jdbc:mysql://localhost/";
  5. public Connection_maker()
  6. {
  7. try
  8. {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. this. conn = java.sql.DriverManager.getConnection(DESTINATION, "root", "");
  11. System.out.println("connected");
  12. }
  13. catch (Exception e)
  14. {
  15. e.printStackTrace();
  16. }
  17. }
  18. public static void main(String[] args)
  19. {
  20. new Connection_maker();
  21. }
  22. }
  23.  
  24. bool isAlive(){
  25. try{
  26. String query = "SELECT 1";
  27. Statement st = this.conn.createStatement(ue);
  28. ResultSet rs = st.executeQuery(query);
  29. return true;
  30. }catch(SQLException e){
  31. // honestly kind of non-specific ??
  32. return false;
  33. }
  34. }
Add Comment
Please, Sign In to add comment