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 commentsNeeded to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
ReplyData Science training in rajaji nagar
Data Science with Python training in chennai
Data Science training in electronic city
Data Science training in USA
Data science training in bangalore
it is not executed....why??
ReplyThis is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
Replydevops training in chennai | devops training in anna nagar | devops training in omr | devops training in porur | devops training in tambaram | devops training in velachery
very nice post..thanks to sharing this information!!!
Replyandroid training in chennai
android online training in chennai
android training in bangalore
android training in hyderabad
android Training in coimbatore
android training
android online training
I really liked your blog post.Much thanks again. Awesome.
Replyjava training
java online training
ConversionConversion EmoticonEmoticon