Skip to content

Instantly share code, notes, and snippets.

@Kishy-nivas
Created January 4, 2018 14:29
Show Gist options
  • Save Kishy-nivas/78f7dd7c5848c1a9ec990fe54fd8b3c4 to your computer and use it in GitHub Desktop.
Save Kishy-nivas/78f7dd7c5848c1a9ec990fe54fd8b3c4 to your computer and use it in GitHub Desktop.
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);}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment