Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package dbms_basic;
  2. import java.sql.*;
  3. public class Dbms_Basic {
  4.  
  5.  
  6. public static void main(String[] args) {
  7. // TODO code application logic here
  8. Connection con=null;
  9. Statement stmt=null;
  10. String url="jdbc:mysql://localhost:3306/student";
  11. String user="root";
  12. String pass="system";
  13. try {
  14. Class.forName("com.mysql.jdbc.Driver");
  15.  
  16. System.out.println("Now connecting to databse...n");
  17. con=DriverManager.getConnection(url,user,pass);
  18. System.out.println("Connected !!!n");
  19. stmt=con.createStatement();
  20. System.out.println("Asking for query...n");
  21. ResultSet rs=stmt.executeQuery("select * from cse");
  22. System.out.println("we got it !!!n");
  23. System.out.println("Time to display it...n");
  24. while(rs.next())
  25. {
  26. System.out.println(rs.getInt(1)+" "+rs.getString(2));
  27.  
  28. }
  29. System.out.println("ok it's done !!!n");
  30. stmt.close();
  31. con.close();
  32. System.out.println("connection close !!!n");
  33.  
  34. } catch (ClassNotFoundException | SQLException e) {System.out.println(e);}
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement