Guest User

Untitled

a guest
Jan 11th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import com.mysql.jdbc.Driver;
  2. import java.sql.*;
  3. class Student{
  4. private String first_name ;
  5. private String last_name;
  6. private int m1,m2,m3;
  7.  
  8. public Student(String f_name , String l_name , int m1,int m2,int m3){
  9. this.first_name = f_name;
  10. this.last_name = l_name;
  11. this.m1 = m1;
  12. this.m2 = m2;
  13. this.m3 = m3;
  14.  
  15. }
  16. }
  17.  
  18.  
  19.  
  20. class DbConnectionExample{
  21. public static void main(String args[]){
  22. try{
  23. Class.forName("com.mysql.jdbc.Driver");
  24. Connection con=DriverManager.getConnection( "jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false","root","root");
  25. //here sonoo is database name, root is username and password
  26. Statement stmt=con.createStatement();
  27. ResultSet rs=stmt.executeQuery("select * from Students ");
  28.  
  29. if (rs.next()){
  30. System.out.println("sid : " + rs.getString("sid"));
  31. System.out.println("sid : " + rs.getString("name"));
  32. System.out.println("sid : " + rs.getString("login"));
  33. System.out.println("sid : " + rs.getInt("age"));
  34. System.out.println("sid : " + rs.getDouble("gpa"));
  35.  
  36.  
  37.  
  38. }
  39.  
  40.  
  41. con.close();
  42. }catch(Exception e){ System.out.println(e);}
  43. }
  44. }
Add Comment
Please, Sign In to add comment