Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MysqlDB{
- public MysqlDB() {}
- public Connection mysqlConnect() {
- try{
- String userName = "daph_admin";
- String password = "gU3:35";
- String url = "jdbc:mysql://domU-12-31-38-00-8E-18.compute-1.internal/daphnie";
- Class.forName ("com.mysql.jdbc.Driver").newInstance();
- Connection conn = DriverManager.getConnection (url,userName,password);
- System.out.println("Database Connection Established");
- return conn;
- }
- catch (Exception e){
- System.err.println ("Cannot connect to database server" + e);
- return null;
- }
- }
- public ResultSet getSearchNames(Connection conn){
- try {
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT name from brands");
- return rs;
- }
- catch (SQLException ex){
- // handle any errors
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("SQLState: " + ex.getSQLState());
- System.out.println("VendorError: " + ex.getErrorCode());
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement