Advertisement
Farahim

main - HW9

Dec 12th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. // Ibrahimli Farahim - HW9
  2.  
  3. import java.sql.*;
  4.  
  5. public class SomeProgram {
  6. public static void main(String[] args) throws SQLException {
  7. connectToAndQueryDatabase("root", "qwerty123");
  8. }
  9.  
  10. public static void connectToAndQueryDatabase(String user, String pass) throws SQLException {
  11. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/world", user, pass);
  12. Statement stmt = con.createStatement();
  13. ResultSet rs = stmt.executeQuery("SELECT * from world.city");
  14. while (rs.next()) {System.out.println(rs.getString("Name"));}
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement