日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【E家园项目】

發(fā)布時(shí)間:2023/12/20 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【E家园项目】 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

登錄

? ? ? ? 1、utils類中連接數(shù)據(jù)庫,創(chuàng)建BaseDao

? ? ? ? 2、entity類寫入用戶實(shí)體:

? ? ? ? 3、Dao類編寫實(shí)現(xiàn)用戶登錄的方法

? ? ? ? 4、用戶接口biz層:IUserBiz . java

? ? ? ? 5、在index.jsp界面中編寫登錄的方法

實(shí)現(xiàn)用戶登錄需運(yùn)用到三層構(gòu)架:utils類、entity類、dao類、biz層

登錄
1、utils類中連接數(shù)據(jù)庫,創(chuàng)建BaseDao

package com.zking.utils;
?
/*
?* 數(shù)據(jù)庫幫助類
?*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
?
public class DBHelper {
? ? // 加載驅(qū)動
? ? static {
? ? ? ? try {
? ? ? ? ? ? Class.forName("oracle.jdbc.driver.OracleDriver");
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }
?
? ? // 建立連接
? ? public static Connection getConn() {
? ? ? ? Connection conn = null;
? ? ? ? try {
? ? ? ? ? ? String url = "jdbc:oracle:thin:@localhost:1521:orc";
? ? ? ? ? ? conn = DriverManager.getConnection(url, "scott", "123");
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? e.printStackTrace();
?
? ? ? ? }
? ? ? ? return conn;
? ? }
?
? ? // 關(guān)閉數(shù)據(jù)庫
? ? public static void myClose(Connection conn, PreparedStatement ps, ResultSet rs) {
? ? ? ? try {
? ? ? ? ? ? if (conn != null && !conn.isClosed()) {
? ? ? ? ? ? ? ? conn.close();
? ? ? ? ? ? }
? ? ? ? ? ? if (ps != null) {
? ? ? ? ? ? ? ? ps.close();
? ? ? ? ? ? }
? ? ? ? ? ? if (rs != null) {
? ? ? ? ? ? ? ? rs.close();
? ? ? ? ? ? }
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
?
? ? }

?
BaseDao . java

package com.zking.utils;
?
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
?
/**
?* 增刪改查通用類
?*?
?* @author ling
?*
?*/
public class BaseDao {
? ? protected ResultSet rs = null;
? ? protected Connection conn = null;
? ? protected PreparedStatement ps = null;
?
? ? /**
? ? ?* 方法功能:通用增刪改
? ? ?*?
? ? ?*/
? ? public int executeUpdate(String sql, Object... objects) {
? ? ? ? int n = 0;
? ? ? ? try {
? ? ? ? ? ? conn = DBHelper.getConn();
? ? ? ? ? ? ps = conn.prepareStatement(sql);
? ? ? ? ? ? for (int i = 0; i < objects.length; i++) {
? ? ? ? ? ? ? ? ps.setObject(i + 1, objects[i]);
? ? ? ? ? ? }
? ? ? ? ? ? n = ps.executeUpdate();
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? System.out.println("DAO增刪改異常");
? ? ? ? ? ? e.printStackTrace();
? ? ? ? } finally {
? ? ? ? ? ? DBHelper.myClose(conn, ps, null);
? ? ? ? }
? ? ? ? return n;
? ? }
?
? ? /**
? ? ?* 方法功能:通用查詢
? ? ?*?
? ? ?*/
? ? public ResultSet executeQuery(String sql, Object... objects) {
? ? ? ? try {
? ? ? ? ? ? conn = DBHelper.getConn();
? ? ? ? ? ? ps = conn.prepareStatement(sql);
? ? ? ? ? ? for (int i = 0; i < objects.length; i++) {
? ? ? ? ? ? ? ? ps.setObject(i + 1, objects[i]);
? ? ? ? ? ? }
? ? ? ? ? ? rs = ps.executeQuery();
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? System.out.println("DAO查詢異常");
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? ? ? return rs;
? ? }
?
? ? /**
? ? ?* 方法功能:獲取指定表的最大ID
? ? ?*?
? ? ?*/
? ? public int getMaxID(String colID, String tableName) {
? ? ? ? String sql = "select nvl(max(" + colID + "),0) from " + tableName;
? ? ? ? ResultSet rs = null;
? ? ? ? try {
? ? ? ? ? ? rs = this.executeQuery(sql);
? ? ? ? ? ? if (rs.next()) {
? ? ? ? ? ? ? ? return rs.getInt(1) + 1;
? ? ? ? ? ? }
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? // TODO: handle exception
? ? ? ? }
? ? ? ? return 0;
? ? }
?
? ? /**
? ? ?* 方法功能:獲取任意表格的總記錄數(shù)
? ? ?*?
? ? ?* @param 表名
? ? ?*/
? ? public int getTableCount(String tableName) {
? ? ? ? int count = 0;
? ? ? ? String sql = "select count(*) from " + tableName;
?
? ? ? ? ResultSet rs = this.executeQuery(sql);
? ? ? ? try {
? ? ? ? ? ? if (rs.next()) {
? ? ? ? ? ? ? ? count = rs.getInt(1);
? ? ? ? ? ? }
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? } finally {
? ? ? ? ? ? DBHelper.myClose(this.conn, this.ps, rs);
? ? ? ? }
? ? ? ? return count;
? ? }

<!-- 登錄 -->
? ? ? ? ? ? ? ? ??

? <c:if test="${empty users }">
? ? ? ? ? ? ? ? ? ? ? ? <form action="dologin.jsp" method="post">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <table style="margin-left: 5px;">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td></td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>登錄名:<input name="username" style="width: 110px;" />
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>密碼 :<input name="password" style="width: 110px;" /></td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <td><input type="image" src="image/button01.gif" /> <img
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? src="image/button02.gif" οnclick="register();" /></td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </table>
? ? ? ? ? ? ? ? ? ? ? ? </form>
? ? ? ? ? ? ? ? ? ? </c:if>
? ? ? ? ? ? ? ? ? ? <c:if test="${not empty users }">
? ? ? ? ? ? ? ? ? ? ? ? <div style="text-align: center;">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <p>歡迎${users.username }回來!</p>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <!-- <h5></h5> -->
? ? ? ? ? ? ? ? ? ? ? ? ? ? <button>修改密碼</button>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <button>個(gè)人中心</button>
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? </c:if>

總結(jié)

以上是生活随笔為你收集整理的【E家园项目】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。