⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admindao.java

📁 图书商城系统
💻 JAVA
字号:
package com.tang.admin.foruse;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class AdminDAO {
	Connection conn = null;

	PreparedStatement pstm = null;

	ResultSet rs = null;

	public void open() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager
					.getConnection("jdbc:mysql://localhost/mydata?user=root&password=124853047");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public ArrayList select(String sqlurl) {
		ArrayList al = new ArrayList();
		try {
			pstm = conn.prepareStatement(sqlurl);
			rs = pstm.executeQuery();
			while (rs.next()) {
				AdminBean userbean = new AdminBean();
				userbean.setId(rs.getInt(1));
				userbean.setUsername(rs.getString(2));
				userbean.setPassword(rs.getString(3));
				al.add(userbean);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			this.close();
		}
		return al;
	}

	public boolean delete(String sqlurl) {
		boolean b = false;
		try {
			pstm = conn.prepareStatement(sqlurl);
			int i = pstm.executeUpdate();
			if (i != 0) {
				b = true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			this.close();
		}
		return b;
	}

	public boolean insert(String sqlurl) {
		boolean b = false;
		try {
			pstm = conn.prepareStatement(sqlurl);
			int i = pstm.executeUpdate();
			if (i != 0) {
				b = true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			this.close();
		}
		return b;
	}

	public boolean jdbcUpdate(String sqlurl) {
		boolean b = false;
		try {
			pstm = conn.prepareStatement(sqlurl);
			int i = pstm.executeUpdate();
			if (i != 0) {
				b = true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			this.close();
		}
		return b;
	}

	public void close() {
		try {
			if (rs != null) {
				rs.close();
			}
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -