JSP和SQL SERVER 2000连接问题

wyxixi78 2004-09-20 10:45:53
使用以下代码测试连接:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433";
String user = "sa";
String password = "123456";
Connection conn = DriverManager.getConnection(url,user,password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "select * from employee";
ResultSet rs = stmt.executeQuery(sql);
错误提示:
org.apache.jasper.JasperException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'employee' 无效。
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:536)


root cause

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'employee' 无效。
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
at org.apache.jsp.sql_test_jsp._jspService(sql_test_jsp.java:79)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:536)


请高手们不吝赐教!!!!
...全文
126 点赞 收藏 16
写回复
16 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
victorylj 2004-09-24
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'employee' 无效。
这句话表明数据库中可能没有这个表,或者表名写错了
回复
wyxixi78 2004-09-24
我明明已经指明数据库了,后面不是有纠正吗?你们都没看。。。。。。:(
回复
gexu 2004-09-24
你没有指定数据库的名字!
回复
jein 2004-09-24
晕,不好意思,我看到你的跟帖了,你最好把该页面的所有代码帖出来
<%@ page import="java.lang.*, java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=gb2312" %>
  <html>
  <body>
  <% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
   String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
   
   String user="sa";
   String password="admin";
   Connection conn= DriverManager.getConnection(url,user,password);
   Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
   String sql="select job_id,job_desc from jobs";
   ResultSet rs=stmt.executeQuery(sql);
   while(rs.next()) { %>
    1:<%=rs.getString(1)%><br>
    2:<%=rs.getString(2)%><br>
  <% } %>
  <% out.print("Success"); %>
  <% rs.close();
   stmt.close();
   conn.close();
  %>
  </body>
  </html>
回复
jein 2004-09-24
楼主,你没有指定是使用哪个数据库啊,程序没有办法执行
String sql = "select * from employee";
这条语句
回复
zawx 2004-09-20
加模式名ado.employee
回复
wyxixi78 2004-09-20
改成,;databasename = pubs就会提示url无效;employee是属于pubs的。
回复
wyxixi78 2004-09-20
我刚才试过查询master数据库中的表就可以,查pubs的就不行,为什么啊?
回复
alpha80 2004-09-20
要看这个表是属于那个database 楼上的楼上正解,;databasename = pubs
看看'employee' 属于那个database
回复
wyxixi78 2004-09-20
有这个表的
回复
wyxixi78 2004-09-20
修正:url = "jdbc:microsoft:sqlserver://localhost:1433;databasename = pubs";
回复
skyboy0720 2004-09-20
已经很清楚了啊!对象名 'employee' 无效。
检查看看连接的数据库下有没有这个表!!!
回复
36397 2004-09-20
靠,靠……

你都没有指明数据库,他肯定说你出错的了。

靠,靠……
回复
victorylj 2004-09-20
这个很简单,只是你连接数据库的时候没有指明要连哪个数据库呀,修改如下:
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pm";
//注:pm为employee表坐在的数据库名
回复
CQ_LW 2004-09-20
我有一个连接类,你试一下
import java.sql.*;
import java.util.*;
import javax.servlet.http.HttpServlet;
/*
*数据连接类
*/

public class DBConn {
private String userid = "sa";
/*连接字符串*/
private String conn_str = "jdbc:microsoft:sqlserver://192.168.2.132:1433;SelectMethod=Cursor;DatabaseName=pubs";
private String pwd = "";
/*sql驱动*/
private String classFor = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
public Connection dConn = null;

java.util.Vector batchSQL = new java.util.Vector();

public DBConn() {
try {
Class.forName(classFor);
dConn = DriverManager.getConnection(conn_str, userid, pwd);
System.out.println("Database connection is connected ! ");
}
catch (Exception ex) {
System.out.println("Database connection is not connected ! ");
System.out.println("DBConn.DBConn" + ex.toString()) ;

}
}
回复
weepp 2004-09-20
上为正解!
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-20 10:45
社区公告
暂无公告