R
riipgah
Unregistered / Unconfirmed
GUEST, unregistred user!
我用的是tomcat5.0+jdk1.4,在classpath中已经设置了连接数据库的jar文件,但下面的程序总是报 org.gjt.mm.mysql.Driver SQLException: No suitable driver ,
如果把代码转换到一个java文件中,加入main函数就可以下常运行,
或把jar文件中的目录解压到 WEB-INF/classes 中就可以正常运行,
难道jsp程序不能找到环境变量中数据库驱动程序吗?
///**************a.jsp********************
<%@page import="java.sql.*"
%>
<%
ResultSet rs;
String sql;
try
{
Class.forName("org.gjt.mm.mysql.Driver"
}
catch(java.lang.ClassNotFoundException e)
{
out.println("ClassNotFoundException: "
out.println(e.getMessage());
}
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/childdb?user=root&password=1"
Statement smt=con.createStatement();
rs=smt.executeQuery ("SELECT * FROM maincontrol"
while(rs.next())
{
out.println(rs.getString(1));
}
}
catch(SQLException e)
{
out.println("SQLException: "
+ e.getMessage());
}
%>
如果把代码转换到一个java文件中,加入main函数就可以下常运行,
或把jar文件中的目录解压到 WEB-INF/classes 中就可以正常运行,
难道jsp程序不能找到环境变量中数据库驱动程序吗?
///**************a.jsp********************
<%@page import="java.sql.*"
%>
<%
ResultSet rs;
String sql;
try
{
Class.forName("org.gjt.mm.mysql.Driver"
}
catch(java.lang.ClassNotFoundException e)
{
out.println("ClassNotFoundException: "
out.println(e.getMessage());
}
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/childdb?user=root&password=1"
Statement smt=con.createStatement();
rs=smt.executeQuery ("SELECT * FROM maincontrol"
while(rs.next())
{
out.println(rs.getString(1));
}
}
catch(SQLException e)
{
out.println("SQLException: "
+ e.getMessage());
}
%>