11.jsp訪問數(shù)據(jù)庫

1.jsp訪問數(shù)據(jù)庫

<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.sql.*" %>
<html>
<head>
    <title>logincheck</title>
</head>
<body>
  <%



           String NAME="root";
           String PWD="密碼";
           String URL = "jdbc:mysql://localhost:3306/user";


              Connection con =null;
              PreparedStatement pstmt=null;
              ResultSet rs=null;

              Class.forName("com.mysql.cj.jdbc.Driver");
              con =DriverManager.getConnection(URL,NAME,PWD);
              //String sql="insert into users values(?,?)";

      String name = request.getParameter("uname");
      String pwd = request.getParameter("upwd");
               out.println(name);
              String sql="select * from users where name='"+name+"'and password='"+pwd+"'";
              pstmt = con.prepareStatement(sql);

              // pstmt.setString(1,"zs");
              // pstmt.setString(2,"abc123");

              rs=pstmt.executeQuery();
              if(rs.next()){
                  out.println("登錄成功");
              }
              else{
                  out.print("登陸失敗");
              }

             /* while (rs.next()){
                  String name = rs.getString("name");
                  String pwd =rs.getString("password");
                  System.out.println(name+"--"+pwd);

              }*/

              // int count= pstmt.executeUpdate();

   /*if(count!=0){
       System.out.println("插入成功");
   }
   else{
       System.out.println("插入失敗");
   }*/
              rs.close();
              pstmt.close();
              con.close();






%>
</body>
</html>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容