Message-ID: <4LLOHI$Gma@bbs.neu.edu.cn>
Subject: java里如何连接到SQLSever2000
Date: Sun, 27 Nov 2005 05:59:31 +0000
From: chxl13@bbs.neu.edu.cn (独自流浪...)
Path: news.cnusenet.org!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-cn.bbs.comp.lang.java.20140731.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!meganewsservers.com!feeder2.on.meganewsservers.com!nntp-server.pubsub.com!news.neu.edu.cn!NEU
Newsgroups: cn.bbs.comp.lang.java
Organization: 白山黑水
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: java/M.1133071170.k0
Lines: 77
Xref: news.cnusenet.org cn.bbs.comp.lang.java:19589

弄了一个上午,装上sp3的补丁和MS的jdbc driver for sp3
这里是测试程序:
import java.lang.*;
import java.io.*;
import java.sql.*;
import java.util.*;

public class tt {

    
    public static void main(String[] args) {
        try
        {
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
        String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pub
s";
        //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        //String url = "jdbc:odbc:mybbs";
        Connection con = DriverManager.getConnection(url,"sa","19851103");
        Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,Res
ultSet.CONCUR_UPDATABLE);
        String sql = "select job_id,job_desc from jobs";
        ResultSet rs = stmt.executeQuery(sql);
        while(rs.next())
        {
            System.out.print("the first is "+rs.getString(1));
            System.out.print("the second is "+rs.getString(2));
        }
        System.out.print("connection ok");
        rs.close();
        con.close();
        stmt.close();
        }
        catch(Exception e)
        {
            System.out.println("can't connect the db.");
            e.printStackTrace();
        }
    
    }

}
这里是异常信息:
can't connect the db.
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]第
 1 行: ' ' 附近有语法错误。
    at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown S
ource)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown S
ource)
    at com.microsoft.jdbc.sqlserver.tds.TDSExecuteRequest.processReplyToken(Un
known Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source
)
    at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(U
nknown Source)
    at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown S
ource)
    at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Sour
ce)
    at com.microsoft.jdbc.base.BaseStatement.executeQuery(Unknown Source)
    at tt.main(tt.java:19)
哪位大虾能帮忙,解决一下
似乎是驱动的问题,但是不知道怎么解决
waiting~~

--

心情有些乱


※ 来源:·白山黑水站 http://bbs.neu.edu.cn·[FROM: 219.216.68.212]