Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. public class JavaDBConnect {
  2.  
  3. public static void main(String[] args) throws SQLException {
  4.  
  5. try {
  6. Class.forName("com.mysql.jdbc.Driver");
  7. Connection con = (Connection) DriverManager.getConnection ("jdbc:mysql://YOUR DB URL", "root", "");
  8.  
  9. Statement stmt = (Statement) con.createStatement();
  10.  
  11. ResultSet rs=stmt.executeQuery("select * from users");
  12.  
  13. while(rs.next())
  14.  
  15. System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
  16. con.close();
  17.  
  18. }
  19. catch(Exception e){
  20. System.out.println(e);
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement