Guest User

Untitled

a guest
Feb 27th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. public class MySQL {
  2.  
  3. private static Connection connection;
  4.  
  5. public static Connection getConnection() throws SQLException {
  6. if (connection != null) if (connection.isValid(1)) return connection; else connection.close();
  7.  
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. } catch (ClassNotFoundException ex) {
  11. ex.printStackTrace();
  12. }
  13. connection = DriverManager.getConnection("jdbc:mysql://<db server ip>:3306/<db name>", "<user>", "<pass>");
  14.  
  15. return connection;
  16. }
  17.  
  18. }
Add Comment
Please, Sign In to add comment