SQL2000 關於 Java JDBC 驅動的安裝和設定

來源:互聯網
上載者:User

1、首先要記得sql2000 要打上sp3以上的補丁.(建議用sp4)
2、裝上SQL Server 2000 Driver for JDBC Service Pack 3
   :http://www.microsoft.com/downloads/details.aspx?FamilyId=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en

 

3、安裝完SQL Server 2000 Driver for JDBC Service Pack 3,它預設安裝在C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC 裡,在C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib 這個目錄裡有三個jar檔案:
msbase.jar,mssqlserver.jar,msutil.jar,一定要記得把這三個檔案copy到你所安裝的jdk下的jre目裡,這裡我以的我的安裝配置進行解說:
我的jdk是jdk1.5.0_09,預設安裝在:
C:\Program Files\Java 裡,在這個C:\Program Files\Java目錄下有兩個檔案夾:
jdk1.5.0_09 目錄 和 jre1.5.0_09目錄,
前面說的的那三個jar檔案一定要copy到jdk1.5.0_09目錄裡下的jre目錄下的lib目錄下的ext目錄下,我這裡的完整路徑為:
C:\Program Files\Java\jdk1.5.0_09\jre\lib\ext

 

 

4、設定classpath,把這個三個jar檔案,加進去

5、sql2000要設定為混合登入模式(windows 和 sql)
 

 

----------------------------------------------------------------------------------------------------------- 

調用樣本JAVA代碼 字串1

----------------------------------------------------------------------------------------------------------

 

 

import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
//import java.*;

字串4

 

class CourseAppl {
   
    private Connection conn;
    private String url;
    private String serverName;
    private String portNumber;
    private String databaseName;
    private String userName;
    private String password;
    private String sql;
   
    CourseAppl() {
       
        url = "jdbc:microsoft:sqlserver://";
        serverName = "localhost";
        portNumber = "1433";
        databaseName = "test";
        userName = "sa";
        password = "";
    }
   
    private String getConnectionUrl() {

 

       
        //System.out.println (url + serverName + ":"
              // + portNumber + ";databaseName="
              //+ databaseName + ";");
        return url + serverName + ":"
               + portNumber + ";databaseName="
               + databaseName + ";";
    }
   
    private Connection getConnection() {
       
        try {
           
            System.out.println (getConnectionUrl()); 字串4
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            //Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDrive");
            conn =
                DriverManager.getConnection(getConnectionUrl(),userName,password);
               
            if(conn != null) {
               
                System.out.println ("資料庫連接成功!");
            }
           

 

        }catch(Exception ce) {
           
            ce.printStackTrace();
            System.out.println ("getConnection() 內部錯誤跟蹤:" +
                                ce.getMessage());
        }
       
        return conn;
    }
   
    public void display() {
       
        try {
           
            conn = getConnection();

            PreparedStatement pstmt =
                conn.prepareStatement("update friends set "+
                "salary = ? where name like ?");
            pstmt.setInt(1,10000);
            pstmt.setString(2,"李四");
            pstmt.executeUpdate();
            System.out.println ("李四的記錄已經被更新!!");
           
            Statement stmt = conn.createStatement();
            ResultSet rs =  stmt.executeQuery("select * from friends");
            if(!rs.next()) {
                System.out.println ("空表,沒有資料!!");
            }else {
               
               
                System.out.print(rs.getString(1) + "\t");
                System.out.print(rs.getString(2) + "\t");
                System.out.print(rs.getInt(3) + "\t"); 字串9
                System.out.print(rs.getDate(4) + "\t");
                System.out.print(rs.getInt(5) + "\t");
                System.out.println ();
               
                while(rs.next()) {
                   
                    System.out.print(rs.getString(1) + "\t");
                    System.out.print(rs.getString(2) + "\t"); 字串6
                    System.out.print(rs.getInt(3) + "\t");
                    System.out.print(rs.getDate(4) + "\t");
                    System.out.print(rs.getInt(5) + "\t");
                    System.out.println ();
                }
            }
           
        }catch(SQLException ce) {
           
            System.out.println (ce);  
        }
    }
   
   
    public static void main(String[] args) {
       
        CourseAppl retObj = new CourseAppl();
        retObj.getConnection();
        retObj.display();
    }
}

 

http://blog.csdn.net/allen_l/archive/2007/01/25/1493155.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.