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:8090"); // webLogic端口IP
env.put(InitialContext.SECURITY_PRINCIPAL, "weblogic"); // webLogic连接用户
env.put(InitialContext.SECURITY_CREDENTIALS, "weblogic");// webLogic密码
InitialContext ctx = new InitialContext(env);
DataSource ds = (DataSource) ctx.lookup("openetdb2"); // JNDI名字
conn = ds.getConnection();
stmt = conn.createStatement();
res = stmt.executeQuery("select * from table");
System.out.println("id------name------address");
while (res.next()) {
int id = res.getInt(1);
String name = res.getString(2).trim();
java.sql.Date date = res.getDate(3);
System.out.println("id="+id + ",name ="+name );
if(date != null)
{
System.out.println(date.toString());
}
}
} catch (SQLException sse) {
System.out.println("sql error!");
} catch (NamingException e) {
System.out.println("namingexception");
}
try {
stmt.close();
conn.close();
} catch (SQLException se) {
}
阅读(958) | 评论(0) | 转发(0) |