Connect to sql server from java with jdbc(windows authentication mode) -


i need connect sql server 2008 java using jdbc 4.0. have simple code:

 class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver");  string connectionurl = "jdbc:sqlserver://localhost;" +     "integratedsecurity=true;";  connection con = drivermanager.getconnection(connectionurl); 

but have error:

    exception in thread "main" com.microsoft.sqlserver.jdbc.sqlserverexception: tcp/ip connection host localhost, port 1433 has failed. error: "connection refused: connect. verify connection properties. make sure instance of sql server running on host , accepting tcp/ip connections @ port. make sure tcp connections port not blocked firewall.". @ com.microsoft.sqlserver.jdbc.sqlserverexception.makefromdrivererror(sqlserverexception.java:190)     @ com.microsoft.sqlserver.jdbc.sqlserverexception.convertconnectexceptiontosqlserverexception(sqlserverexception.java:241) ... 

i follow answer:https://stackoverflow.com/a/12524566/1554397

i added jdbc4.jar in libraries/compile

sql server browser windows service running.

in sql server network configuration selected enebled on tcp/ip properties.

i set tcp address 1433.

on run,vm options put -djava.library.path=my path sqljdbc_auth.dll , copy in jdk ,in bin sqljdbc_auth.dll.

what should do?

edit: when write in cmd telnet localhost 1433 'could not open connection host,on port 1433'

if using window authentication can like:

string url = "jdbc:sqlserver://mypc\\sqlexpress;databasename=mydb;integratedsecurity=true"; class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); connection conn = drivermanager.getconnection(url); 

and add path sqljdbc_auth.dll vm argument (you need sqljdbc4.jar in build path).

take here short step-by-step guide showing how connect sql server java should need more details. hope helps!


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -