Java examples for java.sql:Oracle
get Dev Oracle Connection
import java.sql.Connection; import java.sql.DriverManager; import javax.naming.Context; import javax.naming.InitialContext; import javax.sql.DataSource; import org.apache.log4j.Logger; public class Main{ public static void main(String[] argv) throws Exception{ System.out.println(getDevConnection()); }//from w w w. j a v a2 s .co m private static Logger logger = Logger.getLogger(DataBaseUtil.class); public static Connection getDevConnection() throws Exception { String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=fntr3dev-db.cisco.com)(PORT=1811))(CONNECT_DATA=(SID=FNTR3DEV)(Server=Dedicated)))"; String user = "qqqq"; String pwd = "qwerqwer"; Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection(url, user, pwd); return conn; } public static Connection getConnection(String dataSource) throws Exception { Connection conn = null; logger.debug("<datasource> :" + dataSource); if (null == dataSource) { logger.info("data source is null..."); } else { Context initContext = new InitialContext(); Context envContext = (Context) initContext .lookup("java:/comp/env"); DataSource ds = (DataSource) envContext.lookup("jdbc/" + dataSource); conn = ds.getConnection(); } return conn; } }