Topic: 如何在jbuider中连接sql sever2000数据库

  Print this page

1.如何在jbuider中连接sql sever2000数据库 Copy to clipboard
Posted by: xtfhvso
Posted on: 2005-05-31 11:30

请问如何在jbuider中连接sql sever2000数据库?

2.Re:sql sever [Re: xtfhvso] Copy to clipboard
Posted by: menzy
Posted on: 2005-05-31 12:35

1 ODBC
2. JSQlConnector
3. 还有一个叫Direct什么的东西也可以

最重要的,干吗不用 MySQL,加上图形化管理工具?安全性和速度都比Sqlserver好

3.Re:如何在jbuider中连接sql sever2000数据库 [Re: xtfhvso] Copy to clipboard
Posted by: cj1007
Posted on: 2005-06-14 11:35

看看这个,比较简单。
Getting Started
The first thing you need to do is check that you are set up properly. This involves the following steps:

Install Java and JDBC on your machine.

To install both Java and JDBC, simply follow the instructions for downloading the JDK1.1 (Java Development Kit version 1.1). When you download the JDK1.1, you will get JDBC 1.2 as well. The sample code used in the tutorials was written for JDK1.1.
You can find the latest release (JDK1.1 at the time of this writing) at the following URL:

http://java.sun.com/products/JDK/CurrentRelease

Install a driver on your machine.

Your driver should include instructions for installing it. For JDBC drivers written for specific DBMSs, installation consists of just copying the driver onto your machine; there is no special configuration needed.
The JDBC-ODBC Bridge driver is not quite as easy to set up. If you download either the Solaris or Windows versions of JDK1.1, you will automatically get the JDBC-ODBC Bridge driver, which does not itself require any special configuration. ODBC, however, does. If you do not already have ODBC on your machine, you will need to see your ODBC driver vendor for information on installation and configuration.

Install your DBMS if needed.

If you do not already have a DBMS installed, you will need to follow the vendor's instructions for installation. Most users will have a DBMS installed and will be working with an established database.
[previous] [TOC] [next]



2.2 Setting Up a Database
We will assume that the database COFFEEBREAK already exists. (Creating a database is not at all difficult, but it requires special permissions and is normally done by a database administrator.) When you create the tables used as examples in this tutorial, they will be in the default database. We purposely kept the size and number of tables small to keep things manageable.
Suppose that our sample database is being used by the proprietor of a small coffee house called The Coffee Break, where coffee beans are sold by the pound and brewed coffee is sold by the cup. To keep things simple, also suppose that the proprietor needs only two tables, one for types of coffee and one for coffee suppliers.
First we will show you how to open a connection with your DBMS, and then, since what JDBC does is to send your SQL code to your DBMS, we will demonstrate some SQL code. After that, we will show you how easy it is to use JDBC to pass these SQL statements to your DBMS and process the results that are returned.
For your convenience, the JDBC code used in this chapter can be downloaded from our web site at: http://www.javasoft.com/products/jdbc/book.html
This code has been tested on most of the major DBMS products. However, you may encounter some compatibility problems using it with older ODBC drivers with the JDBC-ODBC Bridge.

[previous] [TOC] [next]



2.3 Establishing a Connection
The first thing you need to do is establish a connection with the DBMS you want to use. This involves two steps: (1) loading the driver and (2) making the connection.

[previous] [TOC] [next]



2.3.1 Loading Drivers

Loading the driver or drivers you want to use is very simple and involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code will load it:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ, you would load the driver with the following line of code:

Class.forName("jdbc.DriverXYZ");
You do not need to create an instance of a driver and register it with the DriverManager because calling Class.forName will do that for you automatically. If you were to create your own instance, you would be creating an unnecessary duplicate.
When you have loaded a driver, it is available for making a connection with a DBMS.
[previous] [TOC] [next]



2.3.2 Making the Connection

The second step in establishing a connection is to have the appropriate driver connect to the DBMS. The following line of code illustrates the general idea:

Connection con = DriverManager.getConnection(

           url, "myLogin", "myPassword");
This step is also simple, with the hardest thing being what to supply for url. If you are using the JDBC-ODBC Bridge driver, the JDBC URL will start with jdbc:odbc:. The rest of the URL is generally your data source name or database system. So, if you are using ODBC to access an ODBC data source called "Fred," for example, your JDBC URL could be jdbc:odbc:Fred. In place of "myLogin" you put the name you use to log in to the DBMS; in place of "myPassword" you put your password for the DBMS. So if you log in to your DBMS with a login name of "Fernanda" and a password of "J8," just these two lines of code will establish a connection:

String url = "jdbc:odbc:Fred";

Connection con = DriverManager.getConnection(url, "Fernanda", "J8");
If you are using a JDBC driver, the documentation will tell you what subprotocol to use, that is, what to put after jdbc: in the JDBC URL. For example, if the driver developer has registered the name acme as the subprotocol, the first and second parts of the JDBC URL will be jdbc:acme:. The driver documentation will also give you guidelines for the rest of the JDBC URL. This last part of the JDBC URL supplies information for identifying the data source.
If one of the drivers you loaded recognizes the JDBC URL supplied to the method DriverManager.getConnection, that driver will establish a connection to the DBMS specified in the JDBC URL. The DriverManager class, true to its name, manages all of the details of establishing the connection for you behind the scenes. Unless you are writing a driver, you will probably never use any of the methods in the interface Driver, and the only DriverManager method you really need to know is DriverManager.getConnection.
The connection returned by the method DriverManager.getConnection is an open connection you can use to create JDBC statements that pass your SQL statements to the DBMS. In the previous example, con is an open connection, and we will use it in the examples that follow.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923