DatabasesAndDrivers

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 FileNetwork: derbyclient.jar
Embedded: derby.jar
Driver ClassnamesNetwork: 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 Fileojdbc14.jar
Driver Classnamesoracle.jdbc.driver.OracleDriver
URL Formatsjdbc:oracle:thin:@<host>[:<port>]:<database>
Example URLjdbc: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 Fileojdbc5.jar (JDK 1.5), ojdbc6.jar (JDK 1.6)
Driver Classnamesoracle.jdbc.driver.OracleDriver
URL Formatsjdbc:oracle:thin:@<host>[:<port>]:<database>
Example URLjdbc: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 Version8.2 Build 506
Driver JAR Filepostgresql-8.2-506.jdbc3.jar
Driver Classnameorg.postgresql.Driver
URL Formatjdbc:postgresql://<host>:<port>/<database>
Example URL jdbc:postgresql://jbrave-pc1.sfbay.sun.com:5432/postgres

MySQL drivers for the MySQL database

Driver LocationBundled 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 Filesmysql-connector-java-5.0.7-bin.jar
Driver Classnamecom.mysql.jdbc.Driver
URL Formatsjdbc:mysql://<host>[:<port>]/<database>
Example URLjdbc: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 VersionMicrosoft SQL Server 2005 JDBC Driver 1.1 sqljdbc_1.1.1501.101_enu.tar.gz
Driver JAR Filesqljdbc.jar
Driver Classnamecom.microsoft.sqlserver.jdbc.SQLServerDriver
URL Formatjdbc:sqlserver://<host>[:<port>];database=<database>;selectMethod=cursor
Example URLjdbc:sqlserver://localhost:1433;databaseName=travel;selectMethod=cursor

IBM driver for the DB2 database

Driver LocationDB2 Personal Developer's Edition: Redistributable JDBC Type 4 Driver (requires registration)
Driver VersionRedistributable DB2 JDBC Type 4 driver v8 fixpack 13
db2_jdbc_t4_fp13.zip
Driver JAR FilesType 4 db2jcc.jar, Type 2 jcc_license_cu.jar
Driver Classnamecom.ibm.db2.jcc.DB2Driver
URL Format (Type 4) jdbc:db2://<host>[:<port>]/<database>
Example URLjdbc:db2://localhost:50002/sample
Note: The IBM drivers support both Type 2 (native) and Type 4 (pure Java). To force the drivers to run in Type 4, add a property: driverType = 4 when connecting to the database. Note2: To execute application, copy db2jcct2.dll or similar to the application server classpath. For Glassfish that would be $GLASSFISH_INSTALL_DIR/domains/domain1/lib

jTDS driver for the SQL Server database

Driver Location jTDS
Driver Version jTDS 1.2.1 jtds-1.2.1-dist.zip
Driver JAR Filejtds-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 LocationDataDirect Connect for JDBC, Release 3.6 Service Pack1
Driver VersionsDataDirect Connect for JDBC - 3.6
DataDirect Connect for JDBC - 3.6.07
Driver .jar Filesbase.jar
util.jar
spy.jar
resource.jar
oracle.jar
sybase.jar
sqlserver.jar
informix.jar
Driver Classnamescom.ddtek.jdbc.oracle.OracleDriver
com.ddtek.jdbc.sqlserver.SQLServerDriver
com.ddtek.jdbc.db2.DB2Driver
com.ddtek.jdbc.sybase.SybaseDriver
URL Formatsjdbc: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 URLsjdbc: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";

如果写法错误将会找不到驱动.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值