Advertisement
Guest User

Untitled

a guest
Apr 5th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. static Connection establishConnection(){
  2. try{
  3. Class.forName("com.mysql.jdbc.Driver"); //The name of the SQL Driver
  4. connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/bapers?useUnicode=true&characterEncoding=utf-8&useSSL=false", username, password); //Create a connection to the database
  5. JOptionPane.showMessageDialog(null, "Connection successful!"); //Show a pop-up dialogue if the connection is successful
  6. return connection;
  7.  
  8. } catch (ClassNotFoundException e) {
  9. e.printStackTrace();
  10. } catch (SQLException e) {
  11. e.printStackTrace();
  12. }
  13. return connection;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement