Advertisement
Guest User

moorzy

a guest
Oct 16th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. package week4;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. public class week4 {
  10.  
  11. public static void main(String[] args) {
  12. try(Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/itb", "root", "Pass$$")){
  13. Statement s = c.createStatement();
  14. ResultSet rs = s.executeQuery("Select * from dept");{
  15. while(rs.next()) {
  16. System.out.printf("%5d%14s%14s",
  17. rs.getInt("DEPTNO"),
  18. rs.getString("DNAME"),
  19. rs.getString("LOC"));
  20. }
  21. }
  22. System.out.println("Success!");
  23. }catch(SQLException e) {
  24. e.printStackTrace();
  25. }
  26.  
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement