您好,登錄后才能下訂單哦!
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
// 導(dǎo)入驅(qū)動(dòng),加載具體驅(qū)動(dòng)類
Class.forName("com.mysql.cj.jdbc.Driver");
// 與數(shù)據(jù)庫建立連接
connection = DriverManager.getConnection(URL, USERNAME, PSW);
// 發(fā)送sql,執(zhí)行增、刪、改
stmt = connection.createStatement();
String name=request.getParameter("uname");
String pwd=request.getParameter("upwd");
//錯(cuò)誤寫法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是數(shù)據(jù)庫中定義的字段名,右邊的name是上面的String name獲取的用戶輸入的值
//錯(cuò)誤寫法2://String sql = "select name,pwd from user where name='name' and pwd='pwd' ";
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。