您好,登錄后才能下訂單哦!
index.jsp
<body>
<form action="check.jsp" method="post">
用戶名<input type="text" name="uname"><br/>
密碼<input type="password" name="upwd"><br/>
<input type="submit" value="登錄"><br/>
</form>
</body>
check.jsp
// 導入驅動,加載具體驅動類
Class.forName("com.mysql.cj.jdbc.Driver");
// 與數據庫建立連接
connection = DriverManager.getConnection(URL, USERNAME, PSW);
// 發送sql,執行增、刪、改
stmt = connection.createStatement();
String name=request.getParameter("uname");
String pwd=request.getParameter("upwd");
//錯誤寫法1://String sql = "select count(*) from user where name=' "+name+" ' and pwd=' "+pwd+" ' ";
String sql = "select count(*) from user where uname=' "+name+" ' and upwd=' "+pwd+" ' ";
// =左邊的uname是數據庫中定義的字段名,右邊的name是上面的String name獲取的用戶輸入的值
//錯誤寫法2://String sql = "select name,pwd from user where name='name' and pwd='pwd' ";
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。