Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.mysql.jdbc.Driver;
- import java.sql.*;
- class Student{
- private String first_name ;
- private String last_name;
- private int m1,m2,m3;
- public Student(String f_name , String l_name , int m1,int m2,int m3){
- this.first_name = f_name;
- this.last_name = l_name;
- this.m1 = m1;
- this.m2 = m2;
- this.m3 = m3;
- }
- }
- class DbConnectionExample{
- public static void main(String args[]){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=DriverManager.getConnection( "jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false","root","root");
- //here sonoo is database name, root is username and password
- Statement stmt=con.createStatement();
- ResultSet rs=stmt.executeQuery("select * from Students ");
- if (rs.next()){
- System.out.println("sid : " + rs.getString("sid"));
- System.out.println("sid : " + rs.getString("name"));
- System.out.println("sid : " + rs.getString("login"));
- System.out.println("sid : " + rs.getInt("age"));
- System.out.println("sid : " + rs.getDouble("gpa"));
- }
- con.close();
- }catch(Exception e){ System.out.println(e);}
- }
- }
Add Comment
Please, Sign In to add comment