传统jdbc获取连接的通用方法

可能是hibernate和ide的关系,
发现目前自己手写jdbc都有些困难了。所以留个脚印
public class DbTools {
        //mysql url= jdbc:mysql://localhost:3306/dbname
	static String url = "jdbc:oracle:thin:@localhost:1521:dbname";
	static String username = "soa";
	static String password = "soa";
	
	public static Connection getConn(){
		Connection conn = null;
		try {
                        //mysql com.mysql.jdbc.Driver
			Class.forName("oracle.jdbc.driver.OracleDriver");
			conn = DriverManager.getConnection(url,username,password);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return conn;
	}

你可能感兴趣的:(oracle,mysql,Hibernate,jdbc,SOA)