ry {
//=================================================================================
Properties props =new Properties();
props.setProperty("user", "system");
props.setProperty("password", "zjxyzken");
Driver myDriver =
(Driver) Class.forName("weblogic.jdbc.pool.Driver").newInstance();
Conn = myDriver.connect("jdbc:weblogic:pool:mysqlPool1",props);
//=================================================================================
Statement Stmt = Conn.createStatement();
ResultSet RS = Stmt.executeQuery("SELECT * from users");
while (RS.next()) {
out.println(RS.getString("userid")+"\\t"
+RS.getString("passwd")
+"\\t"+RS.getString("name"));
}
RS.close();
Stmt.close();
Conn.close();
}catch (Exception E) {
System.err.println("Unable to load driver.");
E.printStackTrace();
}
out.println("</pre></body></html>");
}
}
经过阅读源代码,我们可以发现,作为
程序员某定程度上根本不需要理会服务器装的是什么SQL数据库,
只需连接到weblogic创建提供的POOL就可以了,这样一来除了可以提高效率外还令到代码的可重用性大大提高。