首页>代码>java web物流管理系统>/transform/src/com/wy/JDBConnection.java
package com.wy;

import java.sql.*;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.*;

public class JDBConnection {

	private static Connection conn = null; // 设置Connection类的对象
	private static Statement st = null; // 设置Statement类的对象
	private ResultSet rs = null; // 设置ResultSet类的对象

	private String dbUrl = "jdbc:mysql://localhost:3306/db_wuliu";
	private String dbUserName = "root";
	private String dbPassword = "123456";
	private String jdbcName = "com.mysql.jdbc.Driver";

	/**
	 * 获取数据库连接
	 * 
	 * @return
	 * @throws Exception
	 */
	public Connection getCon() throws Exception {
		Class.forName(jdbcName);
		Connection con = DriverManager.getConnection(dbUrl, dbUserName,
				dbPassword);
		return con;
	}

	public void close(Connection con) throws Exception {
		if (con != null) {
			con.close();
		}
	}

	public ResultSet executeQuery(String sql) throws Exception {
		conn = this.getCon();
		try {
			st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
					ResultSet.CONCUR_READ_ONLY);
			rs = st.executeQuery(sql); // 执行对数据库的查询操作
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Query Exception"); // 在控制台中输入异常信息
		} 
		return rs; // 将查询的结果通过return关键字返回
	}

	public boolean executeUpdata(String sql) {
		try {
			st = conn.createStatement(); // 创建声明对象连接
			st.executeUpdate(sql); // 执行添加、修改、删除操作
			return true; // 如果执行成功则返回true
		} catch (Exception e) {
			e.printStackTrace();
			return false; // 如果执行成功则返回false
		}
	}

}
最近下载更多
xiquyiyuan  LV10 3月26日
qazws123  LV1 2023年6月8日
你们的代码都是我的了  LV16 2022年12月6日
遥遥万里  LV1 2022年8月31日
udbsuududueh  LV5 2022年6月30日
testuser1234567  LV24 2022年6月30日
Hsy605  LV9 2022年6月21日
鸾夜0000  LV2 2022年6月8日
wanglinddad  LV55 2022年5月5日
ForestStone  LV2 2022年4月25日
最近浏览更多
xiquyiyuan  LV10 3月26日
xiao小果  LV13 3月2日
ryadmin123  LV2 2月6日
枯木逢春时 2024年10月10日
暂无贡献等级
TY0165  LV20 2024年6月24日
15719908287  LV10 2024年6月19日
暂无贡献等级
1234567tian  LV2 2024年6月1日
港港hhhhhh  LV1 2024年5月20日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友