Results 1 to 5 of 5
- 04-26-2010, 07:28 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 8
- Rep Power
- 0
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 :(
Overlook:
The SQLserver2008 is located on my local machine
No firewall activated
Enabled VIA and the sqlserver should be listening on 1433
EDIT:
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(); db.dbConnect("jdbc:sqlserver://localhost\\servername/Databases/databasename:1433","sa","password"); } } class DB { public DB() {} public void dbConnect(String db_connect_string, String db_userid, String db_password) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection conn = DriverManager.getConnection( db_connect_string, db_userid, db_password); System.out.println("connected"); } catch (Exception e) { e.printStackTrace(); } } };The code block above is the translation of the first part of the code block below.Java Code:SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: 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
Java Code:[SIZE="2"]com.microsoft.sqlserver.jdbc.SQLServerException: 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 com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at javaapplication3.DB.dbConnect(Main.java:23) at javaapplication3.Main.main(Main.java:9)[/SIZE]Last edited by alexander.s; 04-26-2010 at 08:51 PM.
- 04-27-2010, 05:59 AM #2
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
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 microsoft.com 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 MySQLIf my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
- 05-04-2010, 08:39 AM #3
Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 7
- Rep Power
- 0
Import the driver file.
- 03-12-2011, 11:35 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
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: http://www.microsoft.com/downloads/d...7000d-68d0-453...
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?
-
Please don't hijack another's thread. I invite you to start your own thread on this and ask your question there. Locking this re-animated zombie thread.
Similar Threads
-
JDBC commands for connecting to sqlserver
By sudukrish in forum Advanced JavaReplies: 7Last Post: 04-22-2009, 09:48 AM -
Can't connect using jdbc!!!
By mikep_bluefish in forum JDBCReplies: 1Last Post: 11-26-2008, 10:49 PM -
java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]System Exception: Connection
By Ram_TPS in forum JDBCReplies: 1Last Post: 10-16-2008, 02:09 PM -
connect JDBC to offline database
By nancyhung in forum JDBCReplies: 1Last Post: 04-11-2008, 11:04 PM -
Using JDBC to connect to ORACLE database
By Java Tip in forum Java TipReplies: 0Last Post: 02-10-2008, 11:27 AM


LinkBack URL
About LinkBacks

Bookmarks