日期:2014-05-17 浏览次数:20854 次
/**
* 数据源.
* @time 2012-12-31 09:19:33
*/
package com.DataSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.Exceptions.DB_Exception;
/**
* @author Administrator
*
*/
public final class DataSource {
/**
* . 构造函数.
*/
private DataSource() {
}
/**
* . 静态数据库连接.
*/
private static Connection conn = null;
/**
* @return conn.
* @throws DB_Exception
* Exception.
*/
public static Connection getConnection() throws DB_Exception {
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager
.getConnection(
"jdbc:mysql://192.168.1.104:3306/itao?characterEncoding=gbk",
"qqq", "");
} catch (ClassNotFoundException e) {
// 抛异常
throw new DB_Exception(e);
} catch (SQLException e) {
// 抛异常
throw new DB_Exception(e);
}
if (conn == null) {
throw new DB_Exception("conn为空!!!");
}
return&nbs