| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1645 人关注过本帖
标题:SQLserver2000与JSP连接的问题
只看楼主 加入收藏
giant110
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-2-27
收藏
 问题点数:0 回复次数:6 
SQLserver2000与JSP连接的问题
今天试了一天老连不上,有人说XP中1433端口被屏蔽了,用加载JAVA纯驱动程序连不能,我用JDBC—ODBC桥接器怎么也连不上,数据库运行正常。
代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java"%>
<%@ page import="java.sql.*";import="*";import="java.util.*"%>

<html>
<body bgcolor="cyan">
<% Connection con;
   Statement sql;
    ResultSet rs;
    try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");    }
    catch(ClassNotFoundException e)
    {out.print(e);}
  try {con=DriverManager.getConnection("jdbc:odbc:数据源","用户名","密码");
  sql=con.createStatement();
  rs=sql.executeQuery("select * from xianlu_table where busnum=1");
  while(rs.next())
  {
  /*查询输出语句*/
  }
  con.close();  
%>
</body>
</html>
那地方出错了,难道这种格式不对?望高手指教!
搜索更多相关主题的帖子: JSP JAVA 数据库 java 
2008-03-10 16:39
青格儿
Rank: 4
等 级:贵宾
威 望:11
帖 子:698
专家分:20
注 册:2007-7-31
收藏
得分:0 
你打补定了吗?
没打补定是绝对连不上的!
2008-03-13 20:09
Ethip
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:771
专家分:0
注 册:2008-1-18
收藏
得分:0 
回复 1# 的帖子
楼上说的是一个解决办法,先打个SQL Sever 2000 的补丁
SQL2000-KB884525-SP4-x86-CHS.EXE
2008-03-13 21:07
giant110
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-2-27
收藏
得分:0 
补丁打了 SP4升级补丁,还下了JDBC驱动程序,把三个。jar也拷到了tomcat\common\lib目录下,什么JDK1.5和TOMCAR的环境变量也设置了,测试程序是下面这个

<%@ page import="java.lang.*, *, 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=busdate";
//busdate 为数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select *,from bustable";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) { %>
您的第一个字段内容为:<%=rs.getString(1)%><br>
您的第二个字段内容为:<%=rs.getString(2)%><br>
<% } %>
<% out.print("数据库操作成功,恭喜你"); %>
<% rs.close();
stmt.close();
conn.close();
%>
</body>
</html>


可是有以下错误  不知咋会事
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /test.jsp:9

6: //busdate 为数据库的
7: String user="sa";
8: String password="";
9: Connection conn= DriverManager.getConnection(url,user,password);
10: Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
11: String sql="select *,from bustable";
12: ResultSet rs=stmt.executeQuery(sql);


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
    org.apache.jsp.test_jsp._jspService(test_jsp.java:86)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
    com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
    com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
    com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
    com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
    com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
    java.sql.DriverManager.getConnection(Unknown Source)
    java.sql.DriverManager.getConnection(Unknown Source)
    org.apache.jsp.test_jsp._jspService(test_jsp.java:54)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection refused: connect
    com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
    com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
    com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
    com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
    com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
    java.sql.DriverManager.getConnection(Unknown Source)
    java.sql.DriverManager.getConnection(Unknown Source)
    org.apache.jsp.test_jsp._jspService(test_jsp.java:54)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.

我真愁死了 死活连不上,求求那位大哥大姐帮下忙吧!!!
2008-03-14 08:58
Ethip
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:771
专家分:0
注 册:2008-1-18
收藏
得分:0 
回复 1# 的帖子
你把Java连接数据库的两种方法高混在一起啦!

请仔细阅读此文
https://bbs.bccn.net/viewthread.php?tid=197935
2008-03-15 00:13
Delicious
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-4-11
收藏
得分:0 
我怎么看不明白呢?
2008-04-11 15:04
luyihuaa5201
Rank: 2
等 级:论坛游民
帖 子:254
专家分:10
注 册:2007-3-25
收藏
得分:0 
我连上了  用下面的方法!
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<html>
<body>
<%
try{
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
   out.print(e);
}
try{
   String url = "jdbc:odbc:数据源";
   Connection conn = DriverManager.getConnection(url);
   Statement stmt = conn.createStatement();
   ResultSet rs = stmt.executeQuery("SELECT * FROM t_dept");
   out.println("Dept-list"+"<br>");
   while(rs.next()){
     out.print(rs.getString(1)+" ");
     out.print(rs.getString(2)+"<br>");
   }
   rs.close();
   stmt.close();
   conn.close();
}
catch(Exception ex){
   out.print(ex);
}
%>
</body>
</html>
2008-04-11 16:47
快速回复:SQLserver2000与JSP连接的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.071984 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved