Tested Drivers
NetBeans 6.0 has been tested with the following databases and drivers. (see supported target servers for web applications)
Java DB driver for the JavaDB database
Driver Location | Bundled with Glassfish or Java 6 Also available from http://db.apache.org/derby/releases/release-10.3.1.4.cgi |
Driver Versions | Derby 10.3.1.4 |
Driver JAR File | Network: derbyclient.jar Embedded: derby.jar |
Driver Classnames | Network: org.apache.derby.jdbc.ClientDriver Embedded: org.apache.derby.jdbc.EmbeddedDriver |
URL Format (Network) | jdbc:derby://<host>[:<port>]/<database>[;attr1=value1[;...]] |
Example URL (Network) | jdbc:derby://localhost:1527/sample |
Oracle driver for the Oracle 10.x database
Driver Location | Oracle Database 10g Release 2 JDBC Drivers |
Driver Versions | Oracle Database 10g Release 2 (10.2.0.3) |
Driver JAR File | ojdbc14.jar |
Driver Classnames | oracle.jdbc.driver.OracleDriver |
URL Formats | jdbc:oracle:thin:@<host>[:<port>]:<database> |
Example URL | jdbc:oracle:thin:@localhost:1521:ora9i |
Oracle driver for the Oracle 11.x database
Driver Location | Oracle Database 11g Release JDBC Drivers |
Driver Versions | Oracle Database 11g Release (11.1.0.6.0) |
Driver JAR File | ojdbc5.jar (JDK 1.5), ojdbc6.jar (JDK 1.6) |
Driver Classnames | oracle.jdbc.driver.OracleDriver |
URL Formats | jdbc:oracle:thin:@<host>[:<port>]:<database> |
Example URL | jdbc:oracle:thin:@localhost:1521:ora11i |
PostgreSQL driver for the PostgreSQL database
Driver Location | Bundled with NetBeans 6.0 Also available from http://jdbc.postgresql.org/download.html |
Driver Version | 8.2 Build 506 |
Driver JAR File | postgresql-8.2-506.jdbc3.jar |
Driver Classname | org.postgresql.Driver |
URL Format | jdbc:postgresql://<host>:<port>/<database> |
Example URL | jdbc:postgresql://jbrave-pc1.sfbay.sun.com:5432/postgres |
MySQL drivers for the MySQL database
Driver Location | Bundled with NetBeans 6.0 Also available from http://dev.mysql.com/downloads/connector/j/5.0.html |
Driver Version | MySQL Connector/J 5.0.7 |
Driver JAR Files | mysql-connector-java-5.0.7-bin.jar |
Driver Classname | com.mysql.jdbc.Driver |
URL Formats | jdbc:mysql://<host>[:<port>]/<database> |
Example URL | jdbc:mysql://localhost:3306/sample |
Other Drivers
The following drivers and databases have not been formally tested, but should work based on experience.
Microsoft driver for the SQL Server database
Driver Location | Microsoft SQL Server 2005 JDBC Driver 1.1 |
Driver Version | Microsoft SQL Server 2005 JDBC Driver 1.1 sqljdbc_1.1.1501.101_enu.tar.gz |
Driver JAR File | sqljdbc.jar |
Driver Classname | com.microsoft.sqlserver.jdbc.SQLServerDriver |
URL Format | jdbc:sqlserver://<host>[:<port>];database=<database>;selectMethod=cursor |
Example URL | jdbc:sqlserver://localhost:1433;databaseName=travel;selectMethod=cursor |
IBM driver for the DB2 database
Driver Location | DB2 Personal Developer's Edition: Redistributable JDBC Type 4 Driver (requires registration) |
Driver Version | Redistributable DB2 JDBC Type 4 driver v8 fixpack 13 db2_jdbc_t4_fp13.zip |
Driver JAR Files | Type 4 db2jcc.jar, Type 2 jcc_license_cu.jar |
Driver Classname | com.ibm.db2.jcc.DB2Driver |
URL Format (Type 4) | jdbc:db2://<host>[:<port>]/<database> |
Example URL | jdbc:db2://localhost:50002/sample |
jTDS driver for the SQL Server database
Driver Location | jTDS |
Driver Version | jTDS 1.2.1 jtds-1.2.1-dist.zip |
Driver JAR File | jtds-1.2.1.jar |
Driver Classname | net.sourceforge.jtds.jdbc.Driver |
URL Format | jdbc:jtds:sqlserver://<host>[:<port>][/<database>][;<property>=<value>[;...]] |
Example URL | jdbc:jtds:sqlserver://rave-cheetah.sfbay.sun.com:1433/travel |
DataDirect drivers for the Oracle, SQL Server, DB2 and Sybase databases
Driver Location | DataDirect Connect for JDBC, Release 3.6 Service Pack1 |
Driver Versions | DataDirect Connect for JDBC - 3.6 DataDirect Connect for JDBC - 3.6.07 |
Driver .jar Files | base.jar util.jar spy.jar resource.jar oracle.jar sybase.jar sqlserver.jar informix.jar |
Driver Classnames | com.ddtek.jdbc.oracle.OracleDriver com.ddtek.jdbc.sqlserver.SQLServerDriver com.ddtek.jdbc.db2.DB2Driver com.ddtek.jdbc.sybase.SybaseDriver |
URL Formats | jdbc:datadirect:oracle://server_name[:portNumber];SID=database jdbc:datadirect:sqlserver://server_name[:portNumber];databaseName=database jdbc:datadirect:db2://server_name[:portNumber]/databaseName=database jdbc:datadirect:sybase://server_name[:portNumber] |
Example URLs | jdbc:datadirect:oracle://localhost;SID=ora9i jdbc:datadirect:sqlserver://localhost:1433;DatabaseName=travel;SelectMethod=cursor jdbc:datadirect:db2://localhost:50002;databaseName=sample |
<1> 将JDBC解压缩到任意位置,比如解压到C盘program files下面,并在安装目录里找到sqljdbc.jar文件,得到其路径开始配置环境变量
在环境变量classpath 后面追加 C:/Program Files/Microsoft SQL Server2005 JDBC Driver/sqljdbc_1.2/enu/sqljdbc.jar
<2> 设置SQLEXPRESS服务器:
a.打开SQL Server Configuration Manager -> SQLEXPRESS的协议 -> TCP/IP
b.右键单击启动TCP/IP
c.双击进入属性,把IP地址中的IP all中的TCP端口设置为1433
d.重新启动SQL Server 2005服务中的SQLEXPRESS服务器
e.关闭SQL Server Configuration Manager
<3> 打开刚刚安装好的 SQL Server Management Studio,连接SQLEXPRESS服务器, 新建数据库,起名字为sample
<4> 打开Eclipse
a.新建工程-> java -> java project,起名为Test
b.选择eclipse->窗口->首选项->java->installed JRE 编辑已经安装好的jdk,查找目录添加sqljdbc.jar
c.右键单击目录窗口中的Test, 选择Build Path ->Configure Build Path..., 添加扩展jar文件,即把sqljdbc.jar添加到其中
<5> 编写java代码来测试连接数据库
程序代码:
import java.sql.*;
public class Test {
public static void main(String[] srg) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=sample"; //连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = "123456"; //密码
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful!
} catch (Exception e) {
e.printStackTrace();
}
}
}
注:
1.因为SQLexpress服务器默认是禁用的并且端口号没有配置,所以要进行重新设置
2.如果你以前用java连接sql server 2000的话就要注意了:
在sql server 2000 中加载驱动和URL路径的语句是
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=sample";
而sql server 2005 中加载驱动和url的语句则为
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=sample";
如果写法错误将会找不到驱动.