JSP链接数据库的简单问题!如果用的是ACCESS的话,一定要有装ACCESS才行吗?
我装机子的时候没有装ACCESS,但是好像上课的时候听老师说ACCESS微软的系统都有带类似的意思……具体记不太清楚了代码如下,很简单的显示数据库内容:<%@pageco...
我装机子的时候没有装ACCESS,但是好像上课的时候听老师说ACCESS微软的系统都有带类似的意思……
具体记不太清楚了
代码如下,很简单的显示数据库内容:
<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<html>
<head>
<title>SIMPLE JSP DB HANDLE</title>
</head>
<body bgcolor="ffffff">
<h2>Students</h2>
<table border="1" width="90%">
<tr>
<td width="30">Number</td><td width="40">Name</td><td width="30">Grade</td>
</tr>
<%
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:student"," "," ");
stmt=conn.createStatement();
rs=stmt.excuteQuery("select * from student");
while(rs.next())
{
int number=rs.getInt(1);
String name=rs.getString(2);
int grade=rs.getInt(3);
%>
<tr>
<td><%=number%></td><td><%=name%></td><td><%=grade%></td>
</tr>
<% }/*while*/ %>
</table>
<%
}/*try*/catch(Exception e)
{
out.println(e.getMessage());
}finally{
try
{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}
catch(SQLException sqle)
{
out.println(sqle.getMessage());
}
}//finally
%>
</body>
</html>
错误信息:
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile Note: sun.tools.javac.Main has been deprecated.
F:\tomcat\work\DEFAULT\ROOT\DB_1.java:105: 'try' without 'catch' or 'finally'.
out.write("\r\n\r\n");
^
F:\tomcat\work\DEFAULT\ROOT\DB_1.java:145: Type expected.
} finally {
^
2 errors, 1 warning
at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:873)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:708)
at org.apache.tomcat.facade.JspInterceptor.preInitCheck(JspInterceptor.java:493)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:413)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:874)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:790)
at org.apache.coyote.tomcat3.Tomcat3Adapter.service(Tomcat3Adapter.java:64)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
at java.lang.Thread.run(Thread.java:534)
是哪里有问题呢?我看不出来哪里少了阿……
而且那一段主要的try catch 和finally是从书上原原本本抄下来的……
executeQuery我改了,可是还是一样的错误阿…… 展开
具体记不太清楚了
代码如下,很简单的显示数据库内容:
<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<html>
<head>
<title>SIMPLE JSP DB HANDLE</title>
</head>
<body bgcolor="ffffff">
<h2>Students</h2>
<table border="1" width="90%">
<tr>
<td width="30">Number</td><td width="40">Name</td><td width="30">Grade</td>
</tr>
<%
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:student"," "," ");
stmt=conn.createStatement();
rs=stmt.excuteQuery("select * from student");
while(rs.next())
{
int number=rs.getInt(1);
String name=rs.getString(2);
int grade=rs.getInt(3);
%>
<tr>
<td><%=number%></td><td><%=name%></td><td><%=grade%></td>
</tr>
<% }/*while*/ %>
</table>
<%
}/*try*/catch(Exception e)
{
out.println(e.getMessage());
}finally{
try
{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}
catch(SQLException sqle)
{
out.println(sqle.getMessage());
}
}//finally
%>
</body>
</html>
错误信息:
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile Note: sun.tools.javac.Main has been deprecated.
F:\tomcat\work\DEFAULT\ROOT\DB_1.java:105: 'try' without 'catch' or 'finally'.
out.write("\r\n\r\n");
^
F:\tomcat\work\DEFAULT\ROOT\DB_1.java:145: Type expected.
} finally {
^
2 errors, 1 warning
at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:873)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:708)
at org.apache.tomcat.facade.JspInterceptor.preInitCheck(JspInterceptor.java:493)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:413)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:874)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:790)
at org.apache.coyote.tomcat3.Tomcat3Adapter.service(Tomcat3Adapter.java:64)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
at java.lang.Thread.run(Thread.java:534)
是哪里有问题呢?我看不出来哪里少了阿……
而且那一段主要的try catch 和finally是从书上原原本本抄下来的……
executeQuery我改了,可是还是一样的错误阿…… 展开
2个回答
展开全部
其实可以不用装,可以连到网络上的ACCESS,但一定要有ACCESS给你连。
F:\tomcat\work\DEFAULT\ROOT\DB_1.java:105: 'try' without 'catch' or 'finally'.
他说你 DB_1 这个类105行try完没有catch或者finally哦;Type expected,他说“}”这个东西不知道是啥!!你要改改 DB_1 这个类;你的jsp没错,只不过少些了一个e:
rs=stmt.excuteQuery("select * from student");
应该是:
rs=stmt.executeQuery("select * from student");
-------------^
F:\tomcat\work\DEFAULT\ROOT\DB_1.java:105: 'try' without 'catch' or 'finally'.
他说你 DB_1 这个类105行try完没有catch或者finally哦;Type expected,他说“}”这个东西不知道是啥!!你要改改 DB_1 这个类;你的jsp没错,只不过少些了一个e:
rs=stmt.excuteQuery("select * from student");
应该是:
rs=stmt.executeQuery("select * from student");
-------------^
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询