Weblogic 连接池的问题,郁闷了好久,各位有空来帮小弟看看!
下面的Servlet为什么不能从数据库里读出数据呢?ConnectPool和DataSource都配置好了,测试没有问题。此程序运行只显示:myJDBCReadServlet,也就是说此句
out.println("<h1>myJDBCReadServlet</h1>"); 后面的程序都没有执行。·##¥#¥,请各位指教!
import java.io.*;
import java.sql.*;
import javax.servlet.http.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class myJDBCReadServlet extends HttpServlet {
public void init() {
try {
ctx = new InitialContext();
/* Create a new DataSource by Locating It in the Naming Service:
*/
ds = (javax.sql.DataSource)
ctx.lookup ("MyJNDI");
} catch (Exception E) {
/*
Handle exception here.
*/
System.out.println("Init Error: " + E);
}
}
public void service(HttpServletRequest requ,
HttpServletResponse resp)
throws IOException
{
Connection myConn = null;
try {
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head><title>myJDBCReadServlet</title></head>");
out.println("<body>");
out.println("<h1>myJDBCReadServlet</h1>");
/* Get a new JDBC connection from the DataSource:
*/
myConn = ds.getConnection();
/* Create an Instance of the java.sql.Statement class
and use the factory method called createStatement()
available in the Connection class to create a new statement.
*/
stmt = myConn.createStatement();
/* Use the shortcut method the available in the Statement
class to execute our query. We are selecting all rows
from the EMPLOYEE table.
*/
rs = stmt.executeQuery("SELECT * FROM myuser ");
/* This enumerates all of the rows in the ResultSet and
prints out the values at the columns named ID, NAME,
LOCATION.
*/
while (rs.next()) {
out.println(rs.getInt("user_id") + "- " +
rs.getString("user_name") + "- " +
rs.getString("tel") + "<p>");
}
/* Release the ResultSet and Statement.
*/
rs.close();
stmt.close();
} catch (Exception E) {
/*
Handle exception here.
*/
System.out.println("Service Error: " + E);
} finally {
if (rs != null) {
try { rs.close(); } catch (Exception ignore) {};
}
if (stmt != null) {
try { stmt.close(); } catch (Exception ignore) {};
}
if (myConn != null) {
try { myConn.close(); } catch (Exception ignore) {};
}
}
}
/*
* Local Variables
*/
Context ctx;
DataSource ds;
Statement stmt;
ResultSet rs;
}