I'm using Sql Express in Eclipse
here is the code

import java.sql.*;
public class Login {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("This is my new world");
        //String url = "jdbc:sqlserver://\\SQLEXPRESS;databaseName=pay;integratedSecurity=true";
        String url ="jdbc:sqlserver://SQLEXPRESS;databaseName=pay;integratedSecurity=true";
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            Connection conn = DriverManager.getConnection(url);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }



    }

And the error is

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at Login.main(Login.java:13)
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://SQLEXPRESS;databaseName=pay;integratedSecurity=true
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at Login.main(Login.java:19)

hai chdboy,

please add/include sqljdbc.jar file to your project build path

check it once after adding the jar file to your project

let me know the status

eb77a8e961eaffbe8584791a92471d20

If that is what you are talking about then it's already there.

hai chdboy,
please do as follows

Right click on Your Project
    ->then click on BuildPath
      -> then go to Libraries
       ->then click on Addexternaljar  
       and then click ok 

thats it

It supports
Supported SQL Server Versions:

Microsoft® SQL Server® 2012
Microsoft® SQL Server® 2008 R2
Microsoft® SQL Server® 2008
Microsoft® SQL Server® 2005
Microsoft® SQL Azure

I'm running Express edition

Now after adding sqljdbc4.jar to my project Build path
I'm getting this error

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host SQLEXPRESS, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
    at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
    at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
    at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at Login.main(Login.java:19)

Edited 3 Years Ago by chdboy

well, the good new is: you have the driver. time to sort the rest out, I guess. that message means you do have the appropriate drivers installed, but either your server isn't running, or you've provided a wrong port or server for the server.

I'm creating a connection string in VB.NET (VS2010)and the connection sting works perfectly using the same 'pay'database name ,it is connecting.So it means the SQLEXPRESS is running.

After Getting JTDS and changing in connection URL String

import java.sql.*;
public class Login {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("This is my new world with JDBC Connection string");


        String url ="jdbc:jtds:sqlserver://Danial/pay;instance=SQLEXPRESS";
        System.out.println("Connected!");

        try {
            //Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("Not connected!");
        }
        try {
            Connection conn = DriverManager.getConnection(url);
            //conn.close();
            System.out.println("Not connected!");
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }



    }

I get this error

java.sql.SQLException: Network error IOException: Connection timed out: connect
    at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:434)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:183)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at Login.main(Login.java:24)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:300)
    at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:253)
    at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:329)
    ... 4 more

The problem lies in this code

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

actually, the problem lies in this line:
Connection conn = DriverManager.getConnection(url);

check your stacktrace, it tells you what the exception is, of which type it is, and on which line in your code it is thrown.

here's a link to the official documentation, it contains code examples of each step, maybe that can help you out, but, again: why are you not using the official drivers?

this is a line from your code:
Class.forName("net.sourceforge.jtds.jdbc.Driver");
this is not the driver provided by Microsoft, is it?
to copy-paste from the official examples

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost;database=AdventureWorks;integratedSecurity=true;"
Connection con = DriverManager.getConnection(connectionUrl);

Changed code

DriverManager.getConnection("com.microsoft.sqlserver.jdbc.SQLServerDriver");

Error is

java.sql.SQLException: No suitable driver found for com.microsoft.sqlserver.jdbc.SQLServerDriver
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at Login.main(Login.java:29)

Now where to find the suitable drivers for?

Connection Timeouts (assuming a local network and several client machines) typically result from

a) some kind of firewall on the way that simply eats the packets without telling the sender things like "No Route to host"

b) packet loss due to wrong network configuration or line overload

c) too many requests overloading the server

d) a small number of simultaneously available threads/processes on the server which leads to all of them being taken. This happens especially with requests that take a long time to run and may combine with c).

Hope this helps.

Not hapenning at all :( and I don't have any Firewall .

Edited 3 Years Ago by chdboy

When I hoover my mouse over

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

It shows me

com.microsoft.sqlserver.jdbc.SQLServerDriver


Note: This element has no attached Javadoc and the Javadoc could not be found in the attached source.

But when I click
Project>Generate Javadoc ,it is already created?

Edited 3 Years Ago by chdboy

seems he needs a lesson on the use and love of the classpath before he continues his forrays into the world of JDBC.

If it now compiles but can't find the driver class at runtime, he's failed to add the driver jar to his runtime configuration.

If I Expand sqljdbc4.jar there is com.microsoft.sqlserver.jdbc
but after expanding further I could not find SQLServerDriver part?
where is that located in which class?

learn the difference between path and classpath. READ the documentation that comes with your tools (the JDK...). You're blindly stumbling ahead, with your eyes closed deliberately, in a room full of things that can trip you but won't if only you were willing to look where you're going.
Do NOT assume that just keeping up saying you have a problem without putting in any effort on your part to solve it will make the problem go away.

I have tried many things configuring Eclipse Juno ,and I really don't know that which thing done the trick for me.Now I'm able to conect to the 'master' database not the database I created,atleast I'm connected.

This question has already been answered. Start a new discussion instead.