Create a Jtds Connection String

Create a jTDS connection string

As detailed in the jTDS Frequenlty Asked Questions, the URL format for jTDS is:

jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;...]]

So, to connect to a database called "Blog" hosted by a MS SQL Server running on MYPC, you may end up with something like this:

jdbc:jtds:sqlserver://MYPC:1433/Blog;instance=SQLEXPRESS;user=sa;password=s3cr3t

Or, if you prefer to use getConnection(url, "sa", "s3cr3t"):

jdbc:jtds:sqlserver://MYPC:1433/Blog;instance=SQLEXPRESS

EDIT: Regarding your Connection refused error, double check that you're running SQL Server on port 1433, that the service is running and that you don't have a firewall blocking incoming connections.

jTDS connection string: connect to a MS SQL Server instance with a backslash

Did further research and tests. Found out the correct connection URL string in this case is:

jdbc:jtds:sqlserver://server-name/database_name;instance=instance_name

In my case, the connection string is:

jdbc:jtds:sqlserver://server-name/MSSQL-DB09v1;instance=v1

See jTDS FAQs for more details

Java JDBC JTDS test connection string

You appear to be facing two issues:

Issue 1. It seems that jTDS 1.2 is sufficiently old that you actually do need to call

Class.forName("net.sourceforge.jtds.jdbc.Driver");

before you try to establish the connection.

Issue 2. When you specify the classpath, you need to explicitly include the jTDS jar file. That is, this won't work ...

C:\JavaTest>"\Program Files\Java\jdk1.6.0_45\bin\java.exe" -cp C:/JavaTest Example
1.
Error - net.sourceforge.jtds.jdbc.Driver

... but this works for me:

C:\JavaTest>"\Program Files\Java\jdk1.6.0_45\bin\java.exe" -cp C:/JavaTest;C:/JavaTest/jtds-1.2.jar Example
1.
2.
3.
Connected.
...

How to make use of Trusted_connection property with jTDS driver?

As described in the file README.SSO, you need not specify any credentials.

In order to set up the jTDS driver to use Windows Single Sign On, users
will have to connect without providing a user name and password. This will
only work on Windows.

Driver example:

    // No user name or password in URL or as parameters
DriverManager.getConnection(
"jdbc:jtds:sqlserver://localhost:1433/LionKing");

You need not specify the useNTLMv2 parameter either, if you do it determines the version of NTLM that will be used, not IF NTLM will be used or not.

SQL Server connection using JDBC - JTDS

FYI, LoginTimeout sets how long you wait to establish a connection. Once connected it has no effect. It looks like the jTDS drive implements socketTimeout which I think should cover your condition.

They also implement a socketKeepAlive. I am not familiar with how they implement it but I assume the poll the connection to either keep it open and\or return an exception if it is dropped. I don't think jTDS offers this but some connection failover functionality might be useful as well.

A summary of one implementation



Related Topics



Leave a reply



Submit