时间:2021-07-01 10:21:17 帮助过:30人阅读
1 <%@page import="com.mchange.v2.c3p0.ComboPooledDataSource"%> 2 <%@page import="java.sql.ResultSet"%> 3 <%@page import="java.sql.PreparedStatement"%> 4 <%@page import="java.sql.Statement"%> 5 <%@page import="java.sql.DriverManager"%> 6 <%@page import="java.sql.Connection"%> 7 <%@ page language="java" contentType="text/html; charset=UTF-8" 8 pageEncoding="UTF-8"%> 9 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 10 <html> 11 <head> 12 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 13 <title>Insert title here</title> 14 </head> 15 <body> 16 <% 17 String name = request.getParameter("name"); 18 String password = request.getParameter("password"); 19 try{ 20 //ComboPooledDataSource cp = new ComboPooledDataSource("helloc3p0"); 21 //Connection conn=cp.getConnection(); 22 Class.forName("oracle.jdbc.driver.OracleDriver"); 23 Connection conn = DriverManager.getConnection( 24 "jdbc:oracle:thin:@localhost:1521:orcl ", 25 "test01", "131281huazioo"); 26 String sql = "select * from bankcard where card=?"; 27 PreparedStatement ps = conn.prepareStatement(sql); 28 ps.setString(1, name); 29 ResultSet rs = ps.executeQuery(); 30 String nameRe=null; 31 String passwordRe=null; 32 if(rs.next()){ 33 nameRe=rs.getString("card"); 34 passwordRe=rs.getString("password"); 35 } 36 if(name.equals(nameRe)){ 37 if(password.equals(passwordRe)){ 38 out.write("登录成功!"); 39 }else{ 40 out.write("密码输入错误!"+"<br>"); 41 out.write("<a href=‘Login.jsp‘>"+"返回上一页"+"</a>"); 42 } 43 }else{ 44 out.write("卡号输入错误!"+"<br>"); 45 out.write("<a href=‘Login.jsp‘>"+"返回上一页"+"</a>"); 46 } 47 rs.close(); 48 ps.close(); 49 conn.close(); 50 }catch(Exception e){ 51 e.printStackTrace(); 52 } 53 %> 54 </body> 55 </html>
Jsp练习——连接数据库模拟登录
标签:eth ring doc padding order ansi idt equals 账号