连接池的建立
public class mypooltest {
public static void main(String[] args) {
Statement stmt = null;
Connection conn = null;
ResultSet res = null;
try {
Hashtable env = new Hashtable();
env.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
env.put(InitialContext.PROVIDER_URL, "t3://localhost:7001");
env.put(InitialContext.SECURITY_PRINCIPAL, "yuy");登录到weblgic的用名
env.put(InitialContext.SECURITY_CREDENTIALS, "12345678");密码
InitialContext ctx = new InitialContext(env);
DataSource ds = (DataSource) ctx.lookup("mytest");JNDI名称为mytest
conn = ds.getConnection();
stmt = conn.createStatement();
res = stmt.executeQuery("select * from man");
System.out.println("id------name------address");
while (res.next()) {
int id = res.getInt(1);
String name = res.getString(2);
String address = res.getString(3);
System.out.println(id + "------" + name + "------" + address);
}
}
catch (SQLException sse) {
System.out.println("sql error!");
}
finally {
}
}
}
本文转自 fish_yy 51CTO博客,原文链接:http://blog.51cto.com/tester2test/138721,如需转载请自行联系原作者