wedtorque Ответов: 0

Как реализовать эту систему на основе программирования сокетов и JDBC ?


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 .


Что я уже пробовал:

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();
      
    }


}

}


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)
      {
          
      }
            
    }



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

Suvendu Shekhar Giri

Как насчет хранения данных в СУБД, таких как MySQL, Oracle или SQL Server, и извлечения их при наличии спроса?

wedtorque

Да, данные находятся в базе данных Mysql, только сервер (учитель ) может получить доступ к данным .я не хочу, чтобы клиент (студент)имел прямой доступ к базе данных .

0 Ответов