请问怎么用数据库连接池?是不是数据库连接池在javaSE里面已经实现了,我们只需配置一下?
Context initCtx = new InitialContext();
Context ctx = (Context) initCtx.lookup( "java:comp/env ");
//获取连接池对象
Object obj = (Object) ctx.lookup( "jdbc/OracleDB ");
//类型转换
javax.sql.DataSource ds = (javax.sql.DataSource)obj;
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
String strSql = " insert into test(id,name) values( '00001 ', 'holen ')
";
stmt.executeUpdate(strSql); .........上面的红色字符串代表什么啊?为什么用java:+路径,这个路径是什么?
Context initCtx = new InitialContext();
Context ctx = (Context) initCtx.lookup( "java:comp/env ");
//获取连接池对象
Object obj = (Object) ctx.lookup( "jdbc/OracleDB ");
//类型转换
javax.sql.DataSource ds = (javax.sql.DataSource)obj;
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
String strSql = " insert into test(id,name) values( '00001 ', 'holen ')
";
stmt.executeUpdate(strSql); .........上面的红色字符串代表什么啊?为什么用java:+路径,这个路径是什么?
Context ctx = (Context) initCtx.lookup( "java:comp/env "); 这个是引用服务器(tomcat)下的连接池吧