Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. package library;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class ConnectDBlibrary {
  8. private Connection conn;
  9. private String url;
  10. private String user;
  11. private String pass;
  12. private String db;
  13.  
  14. public ConnectDBlibrary(){
  15. this.db="bnews";
  16. this.url="jdbc:mysql://localhost:3306/"+db+"?useUnicode=true&characterEncoding=UTF-8";
  17. this.user="root";
  18. this.pass="";
  19. }
  20.  
  21.  
  22. public Connection getConnectMysql() {
  23. //nap driver , java<8.0
  24. try{
  25. Class.forName("com.mysql.jdbc.Driver");
  26. conn=DriverManager.getConnection(url, user, pass);
  27. }
  28. catch(ClassNotFoundException | SQLException e){
  29. e.printStackTrace();
  30. }
  31. return conn;
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement