Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. class MysqlDB{
  2. public MysqlDB() {}
  3.  
  4. public Connection mysqlConnect() {
  5. try{
  6. String userName = "daph_admin";
  7. String password = "gU3:35";
  8. String url = "jdbc:mysql://domU-12-31-38-00-8E-18.compute-1.internal/daphnie";
  9. Class.forName ("com.mysql.jdbc.Driver").newInstance();
  10. Connection conn = DriverManager.getConnection (url,userName,password);
  11. System.out.println("Database Connection Established");
  12. return conn;
  13. }
  14. catch (Exception e){
  15. System.err.println ("Cannot connect to database server" + e);
  16. return null;
  17. }
  18. }
  19.  
  20. public ResultSet getSearchNames(Connection conn){
  21. try {
  22. Statement stmt = conn.createStatement();
  23. ResultSet rs = stmt.executeQuery("SELECT name from brands");
  24. return rs;
  25. }
  26. catch (SQLException ex){
  27. // handle any errors
  28. System.out.println("SQLException: " + ex.getMessage());
  29. System.out.println("SQLState: " + ex.getSQLState());
  30. System.out.println("VendorError: " + ex.getErrorCode());
  31. return null;
  32. }
  33.  
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement