Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
I am trying to make a Student management system where teacher can manage all the data of student (insert delete update ) using JDBC. Now this system is also a server where client machine belongs to students . I have implemented the jdbc part and the server- client part

I want serversocket to keep running in the backend so that any student (client ) can fetch his/her detail

I guess it can be done through threading but is not able to understand how .


What I have tried:

C#
StudentServer.java

public class StudentServer{

   public static void main(String[] args) throws Exception {
       int choice;
       Scanner sc = new Scanner(System.in);

       studentDB std = new studentDB();
       std.connection();


       serverSocket socket =new serverSocket();
       socket.createSocket();
       socket.getDetail();
       while(true)
       { 
         System.out.println("WELCOME TO STUDENT MANAGEMENT SYSTEM");
         System.out.println("ENTER OPTION");
         System.out.println("1.INSERT DATA");
         System.out.println("2.DELETE DATA");
         System.out.println("3.UPDATE DATA");
         System.out.println("4.SEARCH DATA");
         System.out.println("5.dISPLAY ALL");
         System.out.println("6.EXIT");
         choice=sc.nextInt();
         switch(choice)
         {
           //all the cases implemented here    
         }


       }

   }

}

class studentDB{
//student jdbc implemented here 
}

class serverSocket{
ServerSocket ss;
 Socket s;
 boolean listeningSocket=true;
 void createSocket() throws Exception
    {
        ss =new ServerSocket(7777);
        while(listeningSocket){
        s=ss.accept();
        System.out.println("connected");
        MiniServer mini = new MiniServer(s);
        mini.start();
        }
    }

    void getDetail() throws Exception
    {
      String returnstr;  
    
      DataInputStream din=new DataInputStream(s.getInputStream());
      int rollNo=din.readInt();
      
      
      studentDB std = new studentDB();
      std.connection();
      returnstr=std.detail(rollNo);
      
      
      DataOutputStream dout= new DataOutputStream(s.getOutputStream());
      dout.writeUTF(returnstr);
      dout.flush();
      dout.close();
      din.close();
      
    }


}

}


C#
class MiniServer extends Thread{

    private Socket s = null;
    String returnstr="";

    public MiniServer(Socket socket) {

        super("MiniServer");
        this.s = socket;

    }

    public void run(){
           
               
      try{ 
      DataInputStream din=new DataInputStream(s.getInputStream());
      int rollNo=din.readInt();
      
      
      studentDB std = new studentDB();
      std.connection();
      returnstr=std.detail(rollNo);
      
      
      DataOutputStream dout= new DataOutputStream(s.getOutputStream());
      dout.writeUTF(returnstr);
      dout.flush();
      dout.close();
      din.close();
      
    }
      catch(Exception e)
      {
          
      }
            
    }



C#
ClientStudent.java is also implemented

how to implement thread over here so that serversocket is always running in backened and can connect to n client
Posted
Comments
Suvendu Shekhar Giri 11-Oct-16 9:20am    
How about storing the data in a RDBMS like MySQL, Oracle or SQL Server and retrieve them when there is a demand?
wedtorque 11-Oct-16 9:24am    
Yes the data is on Mysql database only server (teacher ) can access the data .i dont want client (student)to have direct access to the databse .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900