Overview
jTDS is an open source 100% pure Java (type 4) JDBC 3.0 driver for Microsoft SQL Server (6.5, 7, 2000, 2005 and 2008) and Sybase (10, 11, 12, 15). jTDS is based on FreeTDS and is currently the fastest production-ready JDBC driver for SQL Server and Sybase. jTDS is 100% JDBC 3.0 compatible, supporting forward-only and scrollable/updateable ResultSets, concurrent (completely independent) Statements and implementing all the DatabaseMetaData and ResultSetMetaData methods. Check out the feature matrix for more details.
Quite a few of the commercial JDBC drivers out there are based on jTDS (or FreeTDS), even if they no longer acknowledge this. jTDS has been tested with virtually all JDBC-based database management tools and is the driver of choice for most of these (recommended for DbVisualizer and SQuirreL SQL, distributed with Aqua Data Studio and DataDino). jTDS is also becoming a common choice for enterprise-level applications: it passes both the J2EE 1.3 certification and Hibernate test suites, and is recommended for JBoss, Hibernate, Atlassian JIRA and Confluence and Compiere.
Why use jTDS?
jTDS is free software. jTDS is released under the terms of the GNU LGPL, giving you not only the posibility to debug and tweak it to your own liking but also to use it in and distribute it with your free or commercial applications.
The other "free" choices, the JDBC-ODBC bridge and Microsoft's own JDBC driver are not actually free. If you encounter an issue with any of them you won't be able to fix it yourself and response times from both Microsoft and Sun are anything but short. Also, both of them lack functionality (the Microsoft driver implements JDBC 2.0, while the bridge is just a JDBC 1.0 implementation) and have serious stability problems: the bridge crashes the JVM if the ODBC driver has any problem and Microsoft just has no intention of really supporting Java/JDBC.
jTDS is also the most performant JDBC driver for both SQL Server and Sybase. We have an older benchmark result but we strongly encourage you to download any benchmark published by commercial JDBC driver vendors and see for yourself. Here are a couple of benchmarks you could use: JNetDirect's JDBC Performance Benchmark and i-net Software's BenchTest 2.1 for MS SQL Server.
Anyway, just give it a spin. Get the latest one from here and see whether you like it or not.
jTDS feature matrix
Below is the list of features of jTDS 1.2.
Compliance | |
SQL Server 2005, 2000, 7.0, 6.5 Compliant | Yes |
Sybase 10, 11, 12, 15 Compliant | Yes (not all features available for Sybase) |
JDK 1.4, 1.3 and 1.2 Compliant | Yes |
Sun Certified 100% Pure JavaTM | Yes |
Feature Summary | |
Open Source and Freely Distributable | Yes |
Prepared and Callable Statements | Yes |
Updateable Result Sets | Yes |
Scrolling Result Sets | Yes |
Batch Updates | Yes (fully optimized, single request/response) |
Statement Pooling | Yes |
Full Timeout Support | Yes |
Full Range of Cursor Types | Yes |
Full BLOB and CLOB Support | Yes |
BLOB and CLOB Locator Support | No |
Unlimited Statements per Connection | Yes |
Generated keys retrieval | Yes |
Named parameters | Yes |
Savepoints | Yes |
Parameter metadata | Yes |
RowSet implementation | No (recommended RowSet implementation: Sun reference implementation 1.0.1) |
Metadata caching | Yes (configurable on connection creation) |
J2EE Support | |
JNDI Data Sources | Yes |
Connection Pooling | Yes |
Connection Pool Implementation | No (recommended pool implementations: DBCP and c3p0) |
XA Distributed Transactions | Yes (experimental) |
SQL Server-Specific | |
Optimized Native Protocol Performance | Yes (benchmark results: [1]) |
Windows Authentication | Yes |
SQL Server named instances | Yes |
Ignoring of update counts from triggers | Yes |
Send String data as ASCII/Unicode | Yes |
NTEXT, NCHAR and NVARCHAR Support | Yes |
Named Pipes | Yes (using the filesystem locally and jCIFS over the network) |
SSL Encryption | Yes |
Fast Forward-Only Cursors | Yes |
package com.wcg.sqlserver; import java.sql.*; public class ConnectURL { public static void main(String[] args) { // Create a variable for the connection string. // String connectionUrl = "jdbc:sqlserver://localhost:1433;" + // "databaseName=Test;user=sa;password=pwd"; // String connString = "jdbc:jtds:sqlserver://localhost/Test"; String connString = "jdbc:jtds:sqlserver://localhost:1433;databaseName=Test;user=sa;password=pwd;"; // Declare the JDBC objects. Connection con = null; Statement stmt = null; ResultSet rs = null; try { // Establish the connection. // Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Class.forName("net.sourceforge.jtds.jdbc.Driver"); con = DriverManager.getConnection(connString); // Create and execute an SQL statement that returns some data. // String SQL = "SELECT TOP 10 * FROM Person.Contact"; String SQL = "SELECT * FROM T"; // String sqlInsert = "INSERT INTO t VALUES(N'吴xx111');"; // sqlInsert+=sqlInsert; // stmt = con.createStatement(); // // boolean bResult = stmt.execute(sqlInsert); // System.out.println(bResult); // System.out.println(stmt.getUpdateCount()); rs = stmt.executeQuery(SQL); // Iterate through the data in the result set and display it. while (rs.next()) { System.out.println(rs.getString(1) + " " + rs.getString(2)); } } // Handle any errors that may have occurred. catch (Exception e) { e.printStackTrace(); } finally { if (rs != null) try { rs.close(); } catch (Exception e) { } if (stmt != null) try { stmt.close(); } catch (Exception e) { } if (con != null) try { con.close(); } catch (Exception e) { } } } }