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

📄 dbmade.java

📁 Java购物车及JSTL的应用
💻 JAVA
字号:
package org.qhit.li.store.dbmade;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBMade {

	/**
	 * 连接数据库
	 * 
	 * @return
	 * @throws Exception
	 */
	public static Connection getCon() throws Exception {
		Connection con = null;
		Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
		con = DriverManager
				.getConnection(
						"jdbc:microsoft:sqlserver://localhost:1433;databasename=Store",
						"sa", "");
		return con;
	}

	/**
	 * getStatement
	 * 
	 * @param con
	 * @return
	 * @throws Exception
	 */
	public static Statement getStm(Connection con) throws Exception {
		Statement stm = null;
		stm = con.createStatement();
		return stm;
	}

	/**
	 * getPreparedStatement
	 * 
	 * @param con
	 * @param sql
	 * @return
	 * @throws Exception
	 */
	public static PreparedStatement getPds(Connection con, String sql)
			throws Exception {
		PreparedStatement pds = null;
		pds = con.prepareStatement(sql);
		return pds;
	}

	/**
	 * 数据集
	 * 
	 * @param stm
	 * @param sql
	 * @return
	 * @throws Exception
	 */
	public static ResultSet getRs(Statement stm, String sql) throws Exception {
		ResultSet rs = null;
		rs = stm.executeQuery(sql);
		return rs;
	}

	/**
	 * 关闭
	 * 
	 * @param rs
	 * @param stm
	 * @param con
	 */
	public static void close(ResultSet rs, Statement stm, Connection con) {
		try {
			if (rs != null) {
				rs.close();
			}
			if (stm != null) {
				stm.close();
			}
			if (con != null) {
				con.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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