Results 1 to 5 of 5
  1. #1
    alexander.s is offline Member
    Join Date
    Aug 2008
    Rep Power

    Default Cannot connect to sqlserver 2008 with JDBC

    All I want to do here is to connect to the database.

    So I've disabled my firewall, with the help of the sql server configuration manager I've enabled "VIA" and under tcp/ip->ip-addresses->IPAll. I've set tcp dynamic ports to 0 and the port to 1433. Those were the recommendations that I found from googling.

    my MySQL connection worked straight away, this microsoft stuff is really a pain :(

    The SQLserver2008 is located on my local machine
    No firewall activated
    Enabled VIA and the sqlserver should be listening on 1433
    I'm using Netbeans 6.8 and I've added jtds-1.2.5 and sqljdbc4 to the project.
    I've tried using both drivers with no luck.
    EDIT nr2:
    I forgot to mention that my sql server login account "sa" is activated and works fine, I can log with the sql server management studio with both the windows authentication and the sql server option.

    EDIT nr3:
    Apparently the server isn't listening on port 1433, that was the port number when I googled for sql server 2008. But mine listens on a high port number, I changed my java code and it works..for anyone else trying to make this work, open Microsoft SQL Server Mangement Studio click on Managment -> Sql Server Logs -> Current. Look around for a while and you'll find the line "Server is listening on <servername><port number>"

    Java Code:
    package javaapplication3;
    import java.sql.*;
    public class Main
        public static void main(String[] args)
            DB db = new DB();
    class DB
        public DB() {}
        public void dbConnect(String db_connect_string,
      String db_userid, String db_password)
                Connection conn = DriverManager.getConnection(
        db_connect_string, db_userid, db_password);
            catch (Exception e)
    Java Code:
    SQL Exception:  The TCP/IP connection to the host localhost, port 1433 has failed. 
    Error: "connect timed out. 
    Verify the connection properties, check that an instance of SQL Server is running on the host  and accepting TCP/IP connections at the  port, and that no firewall is blocking TCP connections to the port
    The code block above is the translation of the first part of the code block below.

    Java Code:
    [SIZE="2"] TCP/IP-anslutningen till värddatorn localhost, port 1433 misslyckades. Fel: "Connection refused: connect. Kontrollera anslutningsegenskaperna, att en instans av SQL Server körs på värddatorn som accepterar TCP/IP-anslutningar på porten och att ingen brandvägg blockerar TCP-anslutningar till porten.".
            at java.sql.DriverManager.getConnection(
            at java.sql.DriverManager.getConnection(
            at javaapplication3.DB.dbConnect(
            at javaapplication3.Main.main([/SIZE]
    Last edited by alexander.s; 04-26-2010 at 08:51 PM.

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    Hold on )

    To connect to MS SQL with Java you need to download some special connectors. MS SQL cannot be connected with MySQL connectors.
    Please visit to download the latest MS SQL Server 2008 Java connectors (drivers).
    I recommend this links
    MS SQL 2005 JDBC Driver

    And please read its tutorials because it is much differ thing as for MySQL
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  3. #3
    ideyatech is offline Member
    Join Date
    Apr 2010
    Rep Power


    Import the driver file.

  4. #4
    aska is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default use jdbc

    hello programmers !
    i'm new in this website,so it's my first topic

    i have problem with ueing jdbc in my project
    i know this steps but after that do know!

    Download the newest driver from Microsoft:
    Unpack/unzip the downloaded file. For me, expanding the archive resulted in a folder called sqljdbc_3.0
    Inside the expanded folder is another, called enu (or whatever language was selected with the download from step 1), which contains, among other items, a file called sqljdbc4.jar
    Copy or move sqljdbc4.jar to your Railo 'install' folder (I use Railo on Tomcat and, for me, this is at /Developer/tomcat/railo) ... it'll be the folder that contains a railo.jar file :)
    please some one tell me what must i do to use the driver?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

Similar Threads

  1. JDBC commands for connecting to sqlserver
    By sudukrish in forum Advanced Java
    Replies: 7
    Last Post: 04-22-2009, 09:48 AM
  2. Can't connect using jdbc!!!
    By mikep_bluefish in forum JDBC
    Replies: 1
    Last Post: 11-26-2008, 10:49 PM
  3. Replies: 1
    Last Post: 10-16-2008, 02:09 PM
  4. connect JDBC to offline database
    By nancyhung in forum JDBC
    Replies: 1
    Last Post: 04-11-2008, 11:04 PM
  5. Using JDBC to connect to ORACLE database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-10-2008, 11:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts