当前位置:首页 » 操作系统 » 核对数据库

核对数据库

发布时间: 2023-09-24 13:48:19

A. java链接mysql数据库实现登陆如何验证

//这是我以前写的核对数据库实现登陆的方法,你只看jdbc部分就好,我还特地给你加了点注释x0dx0aString sql = "select username,password from account";x0dx0aString user = request.getParameter("user");x0dx0aString pass = request.getParameter("password");x0dx0aint j = 0;x0dx0aConnection conn = null;x0dx0aPreparedStatement ps = null;x0dx0aResultSet rs = null;x0dx0atry {x0dx0aconn = JDBCTools1.getConnection();x0dx0aps = conn.prepareStatement(sql);x0dx0ars = ps.executeQuery();x0dx0a//从表中查询获取所有账户的用户名&密码的ResultSet 对象x0dx0awhile(rs.next()){x0dx0aint i = 0;x0dx0ax0dx0aString username[] = new String[10];//用户名数组x0dx0aString password[] = new String[10];//密码数组x0dx0ausername[i] = rs.getString(1);x0dx0apassword[i] = rs.getString(2);x0dx0aif(user.equals(username[i])&&pass.equals(password[i])){//比对x0dx0aresponse.getWriter().print("you are welcome!");x0dx0aj++;x0dx0a}else if(user.equals(username[i])&&!pass.equals(password[i])){x0dx0aresponse.getWriter().println("the realy password is :"+ username[i] +","+password[i]+"\r\n");x0dx0aresponse.getWriter().println("and you password is :"+user +","+pass+" :so the username or password may not right");x0dx0aj++;x0dx0a}else{x0dx0acontinue;x0dx0a}x0dx0ai++;x0dx0a}x0dx0aif(j == 0){x0dx0aresponse.getWriter().println("Your username may not be properly");x0dx0a}x0dx0a} catch (Exception e) {x0dx0ae.printStackTrace();x0dx0a}finally{x0dx0aJDBCTools1.release(rs, ps, conn);x0dx0a}x0dx0a//这是我JDBCTools的getConnection方法x0dx0agetConnection{x0dx0aString driverClass = oracle.jdbc.driver.OracleDriver;x0dx0aString jdbcUrl = jdbc:oracle:thin:@localhost:1521:orcl;x0dx0a//你的数据库的用户名密码x0dx0aString user = null;x0dx0aString password = null;x0dx0a// 通过反射创建Driver对象x0dx0aClass.forName(driverClass);x0dx0areturn DriverManager.getConnection(jdbcUrl, user, password);}x0dx0a//这是我JDBCTools的release方法x0dx0apublic static void release(ResultSet rs, Statement statement,x0dx0aConnection conn) {x0dx0aif (rs != null) {x0dx0atry {x0dx0ars.close();x0dx0a} catch (SQLException e) {x0dx0ae.printStackTrace();x0dx0a}x0dx0a}x0dx0ax0dx0aif (statement != null) {x0dx0atry {x0dx0astatement.close();x0dx0a} catch (Exception e2) {x0dx0ae2.printStackTrace();x0dx0a}x0dx0a}x0dx0ax0dx0aif (conn != null) {x0dx0atry {x0dx0aconn.close();x0dx0a} catch (Exception e2) {x0dx0ae2.printStackTrace();x0dx0a}x0dx0a}x0dx0a}

热点内容
我的世界服务器房间号2020电脑版 发布:2025-01-24 01:28:05 浏览:398
微信提示存储空间不足 发布:2025-01-24 01:19:53 浏览:963
安卓电脑管家如何清除缓存 发布:2025-01-24 00:55:42 浏览:148
怎么上传歌曲到qq音乐 发布:2025-01-24 00:45:30 浏览:65
养猫用什么配置 发布:2025-01-24 00:37:58 浏览:812
pythongps 发布:2025-01-24 00:37:51 浏览:813
办公编程鼠标 发布:2025-01-24 00:37:07 浏览:386
wpa加密类型 发布:2025-01-24 00:35:58 浏览:960
如何用批处理实现ftp映射盘符 发布:2025-01-24 00:25:45 浏览:954
win7sql版本 发布:2025-01-24 00:22:16 浏览:499