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

📄 dbconnect.java

📁 企业进销存源码
💻 JAVA
字号:
package com.dao.util;

import java.sql.*;
import java.util.Properties;

/**
 * @author Administrator
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class DbConnect {	
	private Connection conn = null; 
	private String url = "";
	private String drive = "";
	private String user = "";
	private String password = "";
	public DbConnect(){
		try {
			Properties p = new Properties();
			try {
				p.load(
					DbConnect.class.getResourceAsStream(
						"/connection.properties"));

			} catch (Exception e) {
				//e.printStackTrace();
			}
			url = p.getProperty("url");
			drive = p.getProperty("drive");	
			user = p.getProperty("user");
			password = p.getProperty("password");			

		} catch (Exception ex) {
			System.err.print("系统在装载配置文件或查找数据源时产生错误,错误信息:" + ex.getMessage());
		}
	}
	public Connection getConnection() throws Exception{
		try { 
			Class.forName(drive); 
			conn=DriverManager.getConnection(url, user, password); 
			return conn;
		}catch(Exception e){
			e.printStackTrace();
			throw new Exception("数据库连接错误");
		}
	}
}

⌨️ 快捷键说明

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