我的代码如下:(test.jsp)
<%@ page import="java.lang.*,java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=gb2312" %>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs is your database 已经存在的数据库
String user="sa";
String password="123456";
Connection conn= DriverManager.getConnection(url,user,password);
Statement sql=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs;
rs=sql.executeQuery("Select * From authors");
out.println(" Congratulation!");
while(rs.next())
out.println(rs.getString(1));
%>
运行成功,显示:
Congratulation! 172-32-1176 213-46-8915 238-95-7766 267-41-2394 274-80-9391 341-22-1782 409-56-7008 427-17-2319 472-27-2349 486-29-1786 527-72-3246 648-92-1872 672-71-3249 712-45-1867 722-51-5454 724-08-9931 724-80-9391 756-30-7391 807-91-6654 846-92-7186 893-72-1158 899-46-2035 998-72-3567 但是把数据库改成master就不行了,其他的数据库都不行,只有pubs才可以,很奇怪,出现问题如下:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /test.jsp:118: Connection conn= DriverManager.getConnection(url,user,password);
9: Statement sql=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
10: ResultSet rs;
11: rs=sql.executeQuery("Select * From authors");
12: out.println(" Congratulation!");
13: while(rs.next())
14: out.println(rs.getString(1));
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:506)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'authors' 无效。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:843)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
org.apache.jsp.test_jsp._jspService(test_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'authors' 无效。
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSCursorRequest.openCursor(Unknown Source)
com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
com.microsoft.jdbc.base.BaseStatement.executeQuery(Unknown Source)
org.apache.jsp.test_jsp._jspService(test_jsp.java:57)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
<%@ page import="java.lang.*,java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=gb2312" %>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs is your database 已经存在的数据库
String user="sa";
String password="123456";
Connection conn= DriverManager.getConnection(url,user,password);
Statement sql=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs;
rs=sql.executeQuery("Select * From authors");
out.println(" Congratulation!");
while(rs.next())
out.println(rs.getString(1));
%>
运行成功,显示:
Congratulation! 172-32-1176 213-46-8915 238-95-7766 267-41-2394 274-80-9391 341-22-1782 409-56-7008 427-17-2319 472-27-2349 486-29-1786 527-72-3246 648-92-1872 672-71-3249 712-45-1867 722-51-5454 724-08-9931 724-80-9391 756-30-7391 807-91-6654 846-92-7186 893-72-1158 899-46-2035 998-72-3567 但是把数据库改成master就不行了,其他的数据库都不行,只有pubs才可以,很奇怪,出现问题如下:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /test.jsp:118: Connection conn= DriverManager.getConnection(url,user,password);
9: Statement sql=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
10: ResultSet rs;
11: rs=sql.executeQuery("Select * From authors");
12: out.println(" Congratulation!");
13: while(rs.next())
14: out.println(rs.getString(1));
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:506)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'authors' 无效。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:843)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
org.apache.jsp.test_jsp._jspService(test_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'authors' 无效。
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSCursorRequest.openCursor(Unknown Source)
com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
com.microsoft.jdbc.base.BaseStatement.executeQuery(Unknown Source)
org.apache.jsp.test_jsp._jspService(test_jsp.java:57)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
解决方案 »
- 关于EXTJS的学习
- 如何在Tomcat中加载一个重量级的类
- 问个效菜的问题 请求帮助
- 急!!!jsp中怎么得到不提交的表单的数据?
- 关于JSF中的bodycontent
- servlet程序出现了错误,请各位大哥帮忙指导一下,谢谢!!!
- 关于分辨率和滤镜得两个问题
- ssh框架使用的注解,不是*.hbm.xml配置文件,多对多关系生成的中间表怎么才能添加数据?
- 为什么weblogic的console不能保存servlet
- JSP页面的时间存到数据库只有年月日没有时分秒
- 怎样实现用户点击文件链接,只打开文件,而不弹出下载框
- 那位熟悉JSP的朋友,帮我改一下BBS,并且解释一下代码的意思.十分感谢.
11: rs=sql.executeQuery("Select * From authors");
应该是你更换数据库之后SQL语句出错了,改成master数据库之后也应该修改对应的SQL语句吧~
挺明显的啊
对象名 'authors' 无效。