0

ユーザーがログインまたは登録できるソーシャル ネットワーク サイトを作成しようとしています。正しい資格情報でログインすると、ユーザーは友達リストを検索して、友達になるように招待できます。

これまでのところ、2 つの jsp ファイルを作成しました 。1 つの index.jsp [2] UserRegistration.jsp [2]mySQl には、UserInfo テーブルと userRegistration テーブルを含む SocialNetwork スキーマがあります。

[3] src フォルダーで、私の RegistrationServlet は次のようになります。

// ********************************************************************  
    // JDBC driver name and database URL  
    final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
    final String DB_URL = "jdbc:mysql://localhost:3306/SocialNetwork";  
    // ***********************************************************************  
    // Database credentials  
    final String USER = "root";  
    final String PASS = "root";  
    Connection conn = null;  
    Statement stmt = null;  
    try {  
        // Register JDBC driver  
        Class.forName(JDBC_DRIVER);  


        // connection to mySQL server and  Open a connection  
        System.out.println("Connecting to a selected database...");  
        conn = DriverManager.getConnection(DB_URL, USER, PASS);  
        System.out.println("Connected database successfully...");  

        // create a Statement object ()  
        System.out.println("Inserting records into the table...");  
        stmt = conn.createStatement();  


        //  Execute a query  
        String sql = "INSERT INTO SocialNetwork.userInfo"  
                + "(userName, userPW)" + "VALUES('" + nUser + "','" + nPW  
                + "')";  
        int i = stmt.executeUpdate(sql);  
        out.println("Connection successfull.." + i);  

        //Update the Db  
        stmt.executeUpdate(sql);  

                   // executeQuery () method and save it on ResultSet  

        sql = "SELECT * FROM SocialNetwork.userInfo";  

        ResultSet rs = stmt.executeQuery(sql);  


        // check inserted rows in the Db table  
        while (rs.next()) {  
            String Db_Name = rs.getString("userName");  
            String passwordFromDb = rs.getString("userPW");  
            // rs.getString(newPassW)  
            out.println("<br>DbName **" + Db_Name);  
            out.println("->DbPass  **" + passwordFromDb);  

        }  

    } catch (Exception e) {  
        e.printStackTrace();  
    }  

UserLogin サーブレットを UserInfo テーブルに接続して、ユーザーの名前とパスワードが見つかり、 DB で一致した場合、彼/彼女の友達のリストを見ることができるようにするにはどうすればよいでしょうか。

そのユーザー名とパスワードが UserInfo に見つからない場合は、ユーザーが最初に登録する必要があるというメッセージが表示されます。

ユーザーがログインすると、すべてのユーザー名と年齢のリストが表示されます。後で、ユーザーはそのリストからユーザーを選択し、そのユーザーを友人として招待できます。

4

0 に答える 0