关于连接池的问题:我不知道数据库连接池在那个包里面,我在JDK1.4的API手册中找不到? 拜托,这两个类是自己写的!J2EE里面有的DATASOURCE类,是现成的连接池!是在javax.sql包下! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 啊,自己写的!好无知呀#◎¥%◎#¥……能不能给一个DATASOURCE类的例子,多谢了,不给例子也一样给分,别误会呀!! websphere下的一段JDBC2.0的连接try {//Retrieve a DataSource through the JNDI Naming Servicejava.util.Properties parms = new java.util.Properties();parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,com.ibm.websphere.naming.WsnInitialContextFactory”);//Create the Initial Naming Contextjavax.naming.Context ctx = newjavax.naming.InitialContext(parms);//Lookup through the naming service to retrieve a//DataSource object//In this example, SampleDB is the datasourcejavax.sql.DataSource ds =(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/SampleDB");//Obtain a Connection from the DataSourcejava.sql.Connection conn =ds.getConnection();//query the databasejava.sql.Statement stmt = conn.createStatement();java.sql.ResultSet rs =stmt.executeQuery(“SELECT EMPNO, FIRSTNME, LASTNAMEFROM EMPLOYEE”);//process the resultswhile (rs.next()) {String empno = rs.getString(“EMPNO”);String firstnme = rs.getString(“FIRSTNME”);String lastname = rs.getString(“LASTNAME”);// work with results}} catch (java.sql.SQLException sqle) {//handle SQLException} finally {try {if (rs != null) rs.close();} catch (java.sql.SQLException sqle) {//can ignore}try {if (stmt != null) stmt.close();} catch (java.sql.SQLException sqle) {//can ignore}try {if (conn != null) conn.close();} catch (java.sql.SQLException sqle) {//can ignore}} websphere下的一段JDBC2.0的连接try {//Retrieve a DataSource through the JNDI Naming Servicejava.util.Properties parms = new java.util.Properties();parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,com.ibm.websphere.naming.WsnInitialContextFactory”);//Create the Initial Naming Contextjavax.naming.Context ctx = newjavax.naming.InitialContext(parms);//Lookup through the naming service to retrieve a//DataSource object//In this example, SampleDB is the datasourcejavax.sql.DataSource ds =(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/SampleDB");//Obtain a Connection from the DataSourcejava.sql.Connection conn =ds.getConnection();//query the databasejava.sql.Statement stmt = conn.createStatement();java.sql.ResultSet rs =stmt.executeQuery(“SELECT EMPNO, FIRSTNME, LASTNAMEFROM EMPLOYEE”);//process the resultswhile (rs.next()) {String empno = rs.getString(“EMPNO”);String firstnme = rs.getString(“FIRSTNME”);String lastname = rs.getString(“LASTNAME”);// work with results}} catch (java.sql.SQLException sqle) {//handle SQLException} finally {try {if (rs != null) rs.close();} catch (java.sql.SQLException sqle) {//can ignore}try {if (stmt != null) stmt.close();} catch (java.sql.SQLException sqle) {//can ignore}try {if (conn != null) conn.close();} catch (java.sql.SQLException sqle) {//can ignore}} 老师的一张PPT让我会理解成构造函数创建的两个对象相同? Collections.sort()出现“使用了未经检查或不安全的操作” 不写main方法的话,要怎么改呢?学习下 关于有序数组的问题。 一个基础问题请教大家 jawin的问题,希望大侠指点讨论 变量和作用域的不懂问题??? 谁可以帮我解释一下JAVA RMI中根和干之间的关系,及其原理? 关于一个简单的正则表达式。怎么都搞不定。求教 java utf-8 转 gb2312 如何数据库从数据库中取得指定的行数的结果集!----急!!!! download
//Retrieve a DataSource through the JNDI Naming Service
java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,com.ibm.websphere.naming.WsnInitialContextFactory”);
//Create the Initial Naming Context
javax.naming.Context ctx = new
javax.naming.InitialContext(parms);
//Lookup through the naming service to retrieve a
//DataSource object
//In this example, SampleDB is the datasource
javax.sql.DataSource ds =
(javax.sql.DataSource)
ctx.lookup("java:comp/env/jdbc/SampleDB");
//Obtain a Connection from the DataSource
java.sql.Connection conn =
ds.getConnection();
//query the database
java.sql.Statement stmt = conn.createStatement();
java.sql.ResultSet rs =
stmt.executeQuery(“SELECT EMPNO, FIRSTNME, LASTNAME
FROM EMPLOYEE”);
//process the results
while (rs.next()) {
String empno = rs.getString(“EMPNO”);
String firstnme = rs.getString(“FIRSTNME”);
String lastname = rs.getString(“LASTNAME”);
// work with results
}
} catch (java.sql.SQLException sqle) {
//handle SQLException
} finally {
try {
if (rs != null) rs.close();
} catch (java.sql.SQLException sqle) {
//can ignore
}
try {
if (stmt != null) stmt.close();
} catch (java.sql.SQLException sqle) {
//can ignore
}
try {
if (conn != null) conn.close();
} catch (java.sql.SQLException sqle) {
//can ignore
}
}
//Retrieve a DataSource through the JNDI Naming Service
java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,com.ibm.websphere.naming.WsnInitialContextFactory”);
//Create the Initial Naming Context
javax.naming.Context ctx = new
javax.naming.InitialContext(parms);
//Lookup through the naming service to retrieve a
//DataSource object
//In this example, SampleDB is the datasource
javax.sql.DataSource ds =
(javax.sql.DataSource)
ctx.lookup("java:comp/env/jdbc/SampleDB");
//Obtain a Connection from the DataSource
java.sql.Connection conn =
ds.getConnection();
//query the database
java.sql.Statement stmt = conn.createStatement();
java.sql.ResultSet rs =
stmt.executeQuery(“SELECT EMPNO, FIRSTNME, LASTNAME
FROM EMPLOYEE”);
//process the results
while (rs.next()) {
String empno = rs.getString(“EMPNO”);
String firstnme = rs.getString(“FIRSTNME”);
String lastname = rs.getString(“LASTNAME”);
// work with results
}
} catch (java.sql.SQLException sqle) {
//handle SQLException
} finally {
try {
if (rs != null) rs.close();
} catch (java.sql.SQLException sqle) {
//can ignore
}
try {
if (stmt != null) stmt.close();
} catch (java.sql.SQLException sqle) {
//can ignore
}
try {
if (conn != null) conn.close();
} catch (java.sql.SQLException sqle) {
//can ignore
}
}