ah_cai
2003-07-15 15:42
你的JSP代码中:ResultSet rs=mydb.executeQuery(sql);,这里的mydb是怎么来的,应该是beandb类的实例吧,好像没有看到声明哦,把完整的JSP贴出来看看呢

trainking
2003-07-16 13:22
我在weblogic的DOS窗口中看了,出错信息如下:

无法加载驱动程序:org.gjt.mm.mysql.Driver

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClass

Loader.java:178)

at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAw

areClassLoader.java:45)

at java.lang.ClassLoader.loadClass(ClassLoader.java:297)

at java.lang.ClassLoader.loadClass(ClassLoader.java:253)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:120)

at beandb.beandb.<init>(beandb.java:11)

at jsp_servlet._welcomedb._jspService(_welcomedb.java:94)

at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)

at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm

pl.java:263)

at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm

pl.java:200)

at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe

rvletContext.java:2390)

at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm

pl.java:1959)

at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)

at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

打开数据库连接失败!

java.sql.SQLException: No suitable driver

at java.sql.DriverManager.getConnection(DriverManager.java:537)

at java.sql.DriverManager.getConnection(DriverManager.java:177)

at beandb.beandb.executeQuery(beandb.java:18)

at jsp_servlet._welcomedb._jspService(_welcomedb.java:102)

at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)

at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm

pl.java:263)

at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm

pl.java:200)

at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe

rvletContext.java:2390)

at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm

pl.java:1959)

at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)

at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

<2003-7-16 下午01时18分11秒> <Error> <HTTP> <[WebAppServletContext(7861910,beand

b,/beandb)] Servlet failed with Exception

java.lang.NullPointerException

at jsp_servlet._welcomedb._jspService(_welcomedb.java:107)

at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)

at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm

pl.java:263)

at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm

pl.java:200)

at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe

rvletContext.java:2390)

at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm

pl.java:1959)

at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)

at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

>

但我使用单独的java程序连接数据库,同样这些代码却没有问题。

不知到底是怎么回事阿?

附:welcome.jsp程序如下:

<%@page language="java" import="java.sql.*"%>

<jsp:useBean id="mydb" scope="page" class="myconnect.beandb"/>

<%

String sql="select NAME from PhoneBook where ID='3'";

ResultSet rs=mydb.executeQuery(sql);

String name;

name=rs.getString("NAME");

out.println(name);

%>

trainking
2003-07-16 13:24
附:welcome.jsp程序如下:

<%@page language="java" import="java.sql.*"%>

<jsp:useBean id="mydb" scope="page" class="myconnect.beandb"/>

<%

String sql="select NAME from PhoneBook where ID='3'";

ResultSet rs=mydb.executeQuery(sql);

String name;

name=rs.getString("NAME");

out.println(name);

%>

trainking
2003-07-16 13:28
我的jsp文件内容应该没错的。因为从weblogic的错误信息中可以看出,错误好像就在没有找到数据库驱动程序。

可是我同样的程序在单独的java程序中,运行得很好啊。

所以我百思不得其解。

谢谢大家帮我指点:)

robbin
2003-07-16 15:05
把mysql驱动放到\WEB-INF\lib目录下,或者在startWeblogic.cmd脚本的CLASSPATH里面加上mysql驱动的路径。

猜你喜欢