java 链接oracle 数据库_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java 链接oracle 数据库

java 链接oracle 数据库

 2013/7/10 3:35:43  annan211  程序员俱乐部  我要评论(0)
  • 摘要:packageexport.util;importjava.io.IOException;importjava.io.InputStream;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;importjava.util.Properties;publicclassDBUtil{privatestaticStringurl;privatestaticStringdriver
  • 标签:ORA Java 数据库 数据 Oracle
class="java" name="code">package export.util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {

	private static String url;
	private static String driver;
	private static String user;
	private static String password;
	/**
	 * driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mydb
username=root
password=root
	 */
	static{
		InputStream inputStream =
		DBUtil.class.getClassLoader().getResourceAsStream("export/util/db.properties");
		Properties proper = new Properties();
		try {
			proper.load(inputStream);
			driver = proper.getProperty("driver");
			url = proper.getProperty("url");
			user = proper.getProperty("username");
			password = proper.getProperty("password");
		} catch (IOException e) {
			// TODO Auto-generated catch block

			e.printStackTrace();
		}
	}

	public static Connection getConn(){
		Connection conn = null;
		try {
			Class.forName(driver);
			conn = DriverManager.getConnection(url, user, password);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}
}
上一篇: java 导出excel 下一篇: 龙哥卖书
发表评论
用户名: 匿名