将你的出错信息贴来看看? 你能确定你的con建立好了? try: if (con==null) System.out.println("error:connection is null!"
刚刚错了! 将你的出错信息贴来看看? 你能确定你的con建立好了? try: if (con==null) System.out.println("error:connection is null!");
是这样的:500 Servlet Exception java.lang.NullPointerException at _jsp._class._Exam._Exam__jsp._jspService(_Exam__jsp.java, Compiled Code) at com.caucho.jsp.JavaPage.service(JavaPage.java:87) at com.caucho.jsp.JavaPage.subservice(JavaPage.java:81) at com.caucho.jsp.Page.service(Page.java:407) at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:136) at com.caucho.server.http.Invocation.service(Invocation.java:259) at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:146) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java, Compiled Code) at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java, Compiled Code) at com.caucho.server.TcpConnection.run(TcpConnection.java, Compiled Code) at java.lang.Thread.run(Thread.java:479) -------------------------------------------------------------------------------- Resin 1.3.b1 (built Mon Jan 29 19:25:51 PST 2001)
你能确定你的con建立好了?
try:
if (con==null)
System.out.println("error:connection is null!"
将你的出错信息贴来看看?
你能确定你的con建立好了?
try:
if (con==null)
System.out.println("error:connection is null!");
java.lang.NullPointerException
at _jsp._class._Exam._Exam__jsp._jspService(_Exam__jsp.java, Compiled Code)
at com.caucho.jsp.JavaPage.service(JavaPage.java:87)
at com.caucho.jsp.JavaPage.subservice(JavaPage.java:81)
at com.caucho.jsp.Page.service(Page.java:407)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:136)
at com.caucho.server.http.Invocation.service(Invocation.java:259)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:146)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java, Compiled Code)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java, Compiled Code)
at com.caucho.server.TcpConnection.run(TcpConnection.java, Compiled Code)
at java.lang.Thread.run(Thread.java:479)
--------------------------------------------------------------------------------
Resin 1.3.b1 (built Mon Jan 29 19:25:51 PST 2001)
import="java.sql.*, java.util.Date, java.util.Random"%>
<%!
Connection con = null; //³õʼ»¯ÉèÖÃ×ÊÁÏ¿âÁ´½ÓÏà¹Ø¶ÔÏó
Statement stmt = null;
ResultSet rs = null;public void jspInit() //Ö´ÐÐ×ÊÁÏ¿âÓëÏà¹Ø×ÊÁϵijõʼ»¯
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//ÔØÈëÇý¶¯³ÌÐòÀà±ð con = DriverManager.getConnection("jdbc:odbc:ClassDB");
//½¨Á¢×ÊÁÏ¿âÁ´½Ó stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
//½¨Á¢Statement¶ÔÏó, ²¢ÉèÖüǼָ±êÀàÐÍΪ¿ÉÇ°ºóÒƶ¯
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}public void jspDestroy() //Ö´Ðйرո÷ÖÖ¶ÔÏóµÄ²Ù×÷
{
try{
rs.close(); //¹Ø±ÕResultSet¶ÔÏó
stmt.close(); //¹Ø±ÕStatement¶ÔÏó
con.close(); //¹Ø±ÕConnection¶ÔÏó
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
%>
<%@ page contentType="text/html; charset=GB2312"
import="java.sql.*, java.util.Date, java.util.Random"%>
<%!
Connection con = null;
Statement stmt = null;
ResultSet rs = null;public void jspInit()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:ClassDB");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}public void jspDestroy()
{
try{
rs.close();
stmt.close();
con.close();
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
%>
resin 2.0.0
程序没有问题,你看看你的数据愿对吗?注意大小写的问题
还有如果你的数据库有用户名和密码的话,也要在程序里加上