Practical : 6
Subject : Advanced Java
Aim : Implement Student information system using JDBC and RMI JDBC/Servlet
StudentI.java Code:
--------------------------------------------------------------------------------
import java.rmi.Remote;
import java.sql.*;
import java.util.*;
public interface StudentI extends Remote
{
public abstract ArrayList insert(int id,String name,String branch,int atd) throws Exception;
}
import java.sql.*;
import java.util.*;
public interface StudentI extends Remote
{
public abstract ArrayList insert(int id,String name,String branch,int atd) throws Exception;
}
--------------------------------------------------------------------------------
StudentC.java Code:
--------------------------------------------------------------------------------
import java.sql.*;
import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
public class StudentC extends UnicastRemoteObject implements StudentI
{
public StudentC() throws Exception
{
super();
}
public ArrayList insert(int id,String name,String branch,int atd) throws Exception
{
ArrayList ar=new ArrayList();
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","birju");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into student values("+id+",'"+name+"','"+branch+"',"+atd+")");
ResultSet rs=stmt.executeQuery("select * from student where id="+id);
rs.next();
int Id=rs.getInt(1);
name=rs.getString(2);
branch=rs.getString(3);
atd=rs.getInt(4);
ar.add(new Integer(Id));
ar.add(name);
ar.add(branch);
ar.add(new Integer(atd));
con.close();
return ar;
}
}
import java.sql.*;
import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
public class StudentC extends UnicastRemoteObject implements StudentI
{
public StudentC() throws Exception
{
super();
}
public ArrayList insert(int id,String name,String branch,int atd) throws Exception
{
ArrayList ar=new ArrayList();
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","birju");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into student values("+id+",'"+name+"','"+branch+"',"+atd+")");
ResultSet rs=stmt.executeQuery("select * from student where id="+id);
rs.next();
int Id=rs.getInt(1);
name=rs.getString(2);
branch=rs.getString(3);
atd=rs.getInt(4);
ar.add(new Integer(Id));
ar.add(name);
ar.add(branch);
ar.add(new Integer(atd));
con.close();
return ar;
}
}
--------------------------------------------------------------------------------
Server.java Code:
--------------------------------------------------------------------------------
import java.rmi.*;
public class Server
{
public static void main(String args[]) throws Exception
{
StudentI obj=new StudentC();
Naming.rebind("stinfo",obj);
System.out.println("Server Started");
}
}
--------------------------------------------------------------------------------
import java.rmi.*;
public class Server
{
public static void main(String args[]) throws Exception
{
StudentI obj=new StudentC();
Naming.rebind("stinfo",obj);
System.out.println("Server Started");
}
}
--------------------------------------------------------------------------------
Client.java Code:
--------------------------------------------------------------------------------
import java.rmi.*;
import java.sql.*;
import java.util.*;
public class Client
{
public static void main(String args[]) throws Exception
{
Scanner scan= new Scanner(System.in);
System.out.println("Enter id,name,branch,attendance for student:");
int id=scan.nextInt();
String name=scan.next();
String branch=scan.next();
int atd=scan.nextInt();
StudentI obj=(StudentI)Naming.lookup("stinfo");
ArrayList ar=obj.insert(id,name,branch,atd);
Iterator it=ar.iterator();
System.out.println("Id\tName\tBranch\tAttendance");
System.out.println(it.next()+"\t"+it.next()+"\t"+it.next()+"\t"+it.next()+"\t");
}
}
--------------------------------------------------------------------------------
import java.rmi.*;
import java.sql.*;
import java.util.*;
public class Client
{
public static void main(String args[]) throws Exception
{
Scanner scan= new Scanner(System.in);
System.out.println("Enter id,name,branch,attendance for student:");
int id=scan.nextInt();
String name=scan.next();
String branch=scan.next();
int atd=scan.nextInt();
StudentI obj=(StudentI)Naming.lookup("stinfo");
ArrayList ar=obj.insert(id,name,branch,atd);
Iterator it=ar.iterator();
System.out.println("Id\tName\tBranch\tAttendance");
System.out.println(it.next()+"\t"+it.next()+"\t"+it.next()+"\t"+it.next()+"\t");
}
}
--------------------------------------------------------------------------------
Sign up here with your email
5 comments
Write commentsNo more live link in this comments field
Replyit is not executed....why??
ReplyNo more live link in this comments field
ReplyNo more live link in this comments field
ReplyNo more live link in this comments field
ReplyConversionConversion EmoticonEmoticon