当前位置:首页 > 开发 > 编程语言 > Java > 正文

java 链接oracle 数据库

发表于: 2013-07-09   作者:annan211   来源:转载   浏览:
摘要: 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.Propertie
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 链接oracle 数据库

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号