Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class DatabaseConnection {
  4.  
  5. String driver="com.mysql.jdbc.Driver";
  6. String url="jdbc:mysql://localhost:3306/dataName";
  7. String user="?";
  8. String password="?";
  9.  
  10. public Connection getConnection() {
  11. Connection conn=null;
  12.  
  13. try {
  14. Class.forName(driver);
  15. conn=DriverManager.getConnection(url,user,password);
  16.  
  17. } catch(ClassNotFoundException e) {
  18. e.printStackTrace();
  19. } catch(SQLException e) {
  20. e.printStackTrace();
  21. }
  22.  
  23. return conn;
  24.  
  25.  
  26. }
  27.  
  28. public static void main(String[] args) throws SQLException {
  29.  
  30. DatabaseConnection dc=new DatabaseConnection();
  31. Connection cc=dc.getConnection();
  32. System.out.println(cc);
  33. cc.close();
  34.  
  35. }
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement