當前位置:首頁 » 操作系統 » 核對資料庫

核對資料庫

發布時間: 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}

熱點內容
少兒編程排行 發布:2025-01-24 04:40:46 瀏覽:698
搭建伺服器怎麼使用 發布:2025-01-24 04:19:34 瀏覽:444
平行進口霸道哪些配置有用 發布:2025-01-24 04:19:32 瀏覽:873
ngram演算法 發布:2025-01-24 04:03:16 瀏覽:658
迷宮游戲c語言 發布:2025-01-24 03:59:09 瀏覽:358
榮耀30pro存儲類型 發布:2025-01-24 03:54:02 瀏覽:556
客戶端文件上傳 發布:2025-01-24 03:48:44 瀏覽:257
推特更改密碼的用戶名是什麼 發布:2025-01-24 03:45:55 瀏覽:596
cc編譯選項 發布:2025-01-24 03:45:18 瀏覽:512
銀行密碼怎麼被鎖 發布:2025-01-24 03:37:02 瀏覽:431