Guest User

Untitled

a guest
Feb 7th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class DatabaseConnection {
  4.  
  5. public static void main(String[] args) throws ClassNotFoundException, SQLException {
  6. // TODO Auto-generated method stub
  7. String dbURL= "jdbc:mysql://127.0.0.1:3036/auto";
  8. String username = "root";
  9. String password = "root";
  10. String query = "SELECT * FROM auto.employee";
  11. DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  12. Connection con = DriverManager.getConnection(dbURL,username,password);
  13. Statement stmt= con.createStatement();
  14. ResultSet rs= stmt.executeQuery(query);
  15. String result = rs.toString();
  16. System.out.println(result);
  17. while (rs.next()){
  18. String myName = rs.getString(1);
  19. String myAge = rs.getString(2);
  20. System. out.println(myName+" "+myAge);
  21. }
  22. con.close();
  23. }
  24. }
Add Comment
Please, Sign In to add comment