JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » JDBC/SQL討論區 » JDBC 應用  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 使用 JDBC 連接 MicroSoft SQL 2000 database 的方式
mick





發文: 4
積分: 1
於 2005-11-24 10:01 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
這是自己研究使用 JDBC 連接 MicroSoft SQL 2000 database 的方式,提供給大家參考看看..

1.需要先安裝 Microsoft SQL Server 2000 Driver for JDBC.
http://www.microsoft.com/downloads/details.aspx?familyid=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en

2.另外要設定 ClassPath
set CLASSPATH=.;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Query1.java:  Query MicroSoft SQL 2000 database using JDBC.
 
import java.*;
import java.sql.*;
 
class Query1 {
    
    public static void main (String[] args) {
 
        try {
            
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
            String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TESTDB"; 
            
            String user="sa"; 
            String password="password"; 
            Connection conn= DriverManager.getConnection(url,user,password);
 
            Statement stmt = conn.createStatement();
            ResultSet rs;
            
            rs = stmt.executeQuery("SELECT Name FROM zDBUseReport");
            while ( rs.next() ) {
                String lastName = rs.getString("Name");
                System.out.println(lastName);
 
            }
            conn.close();
        } catch (Exception e) {
            System.err.println("Got an exception! ");
            System.err.println(e.getMessage());
        }
        
    }
 
}


mick edited on 2005-11-24 10:09
reply to postreply to post
作者 Re:使用 JDBC 連接 MicroSoft SQL 2000 database 的方式 [Re:mick]
ajax

Thiago Alves



發文: 675
積分: 3
於 2005-11-24 13:26 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
給你拍拍手!!!
不過
http://www.javaworld.com.tw/jute/post/view?bid=21&id=366&sty=1&tpg=1&age=0
這裡已經有了..
ajax.chien


reply to postreply to post
» JWorld@TW »  JDBC/SQL討論區 » JDBC 應用

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8