Organizational Research By

Surprising Reserch Topic

cannot connect to sqlserver database in java application

cannot connect to sqlserver database in java application  using -'java,sql-server-2008,jdbc'

I have connecting to my database in a JSF web application that I am trying to develop.
Using Windows 7, NetBeans 6.9.1, SQLServer 2008, Glassfish 3.3.

I am using the sqljdbc4.jar driver that I copied from my XP system where I have successfully connected to SQLServer 2005.

I have verified that SQLServer 2008 is running on my system and I can connect to the database through SQL Server Management Studio using the username and password that I am trying to use in the application.  The SQL Server Configuration Manager shows the IP connection port is 1433.  So I think my database is set up properly.

I think I am doing things correctly, but I just can't connect to the database.
Does anyone have any suggestions as to why this is failing and what I can check?


Here is my connection code:

public void connectDB()
        String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=ROVRDEV;user=rovrdevuser;password=rovrdevuser";
        Connection con = DriverManager.getConnection(connectionUrl);
        System.out.println("Database connection = "+con );
    catch( Exception e )
        System.out.println( "Error connecting to database.  Error: "+e.getMessage() );


When I attempt to run this, I get the following exception in the server log:

SEVERE: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. 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.".
    at java.sql.DriverManager.getConnection(
    at java.sql.DriverManager.getConnection(
    at rmsbackoffice.SessionBean1.connectDB(
    at rmsbackoffice.SessionBean1.doInit(
    at rmsbackoffice.SessionBean1.beforePhase(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at com.sun.el.parser.AstValue.invoke(
    at com.sun.el.MethodExpressionImpl.invoke(
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(
    at org.jboss.weld.el.WeldMethodExpression.invoke(
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(
    at javax.faces.component.UIViewRoot.notifyPhaseListeners(
    at javax.faces.component.UIViewRoot.notifyBefore(
    at javax.faces.component.UIViewRoot.encodeBegin(
    at javax.faces.component.UIComponent.encodeAll(
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(
    at com.sun.faces.application.view.MultiViewHandler.renderView(
    at javax.faces.application.ViewHandlerWrapper.renderView(
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(
    at com.sun.faces.lifecycle.Phase.doPhase(
    at com.sun.faces.lifecycle.LifecycleImpl.render(
    at javax.faces.webapp.FacesServlet.service(
    at org.apache.catalina.core.StandardWrapper.service(
    at org.apache.catalina.core.StandardWrapperValve.invoke(
    at org.apache.catalina.core.StandardContextValve.invoke(
    at org.apache.catalina.core.StandardPipeline.doInvoke(
    at org.apache.catalina.core.StandardPipeline.invoke(
    at com.sun.enterprise.web.WebPipeline.invoke(
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.connector.CoyoteAdapter.doService(
    at org.apache.catalina.connector.CoyoteAdapter.service(
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(
    at com.sun.grizzly.http.ProcessorTask.doProcess(
    at com.sun.grizzly.http.ProcessorTask.process(
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(
    at com.sun.grizzly.DefaultProtocolChain.execute(
    at com.sun.grizzly.DefaultProtocolChain.execute(
    at com.sun.grizzly.http.HttpProtocolChain.execute(
    at com.sun.grizzly.ProtocolChainContextTask.doCall(
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(
    at com.sun.grizzly.util.AbstractThreadPool$


asked Oct 19, 2015 by sujata naik
0 votes

Related Hot Questions

4 Answers

0 votes
answered Oct 19, 2015 by kotmus2002
0 votes
answered Oct 19, 2015 by santosh soni
0 votes
answered Oct 19, 2015 by 20shahi
0 votes
answered Oct 19, 2015 by mca.agarwal