#What's causing my JDBC connection to fail.

9 messages · Page 1 of 1 (latest)

round zealot
#

My TCP ports are open. I think it's something wrong with my connectionn string. I think i have been looking at it too long and now i am blind.

public static ResultSet getNames(String name){
PreparedStatement stat;
ResultSet names;

    try {
        RowSetFactory fact = RowSetProvider.newFactory();
        CachedRowSet crs= fact.createCachedRowSet();
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        try (Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;encrypt=true;integratedSecurity=true;databaseName=Northwind;")) { 
            stat = conn.prepareStatement(name);
            names = stat.executeQuery();
            crs.populate(names);
            System.out.print("Connection successful.");
            conn.close();
            return crs;
        }

        
    } catch (SQLException | ClassNotFoundException ex) {
        Logger.getLogger(DatabaseSchema.class.getName()).log(Level.SEVERE, null, ex);
        System.out.print("Connection failed.");
        return null;
    }

}

slender vortexBOT
#

This post has been reserved for your question.

Hey @round zealot! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

proper slate
#

do you need a username and password for ur db?

round zealot
#

Its local so it shouldn't.

proper slate
#

whats the exception?

round zealot
#

SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "connect timed out. 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.".

#

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 127.0.0.1, port 1433 has failed. Error: "connect timed out. 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:237)
at com.microsoft.sqlserver.jdbc.SQLServerException.convertConnectExceptionToSQLServerException(SQLServerException.java:288)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2574)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:715)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:3427)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:3077)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:2919)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1787)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1229)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at databaseschema.DatabaseSchema.getNames(DatabaseSchema.java:68)
at databaseschema.DatabaseSchema.main(DatabaseSchema.java:41)

slender vortexBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.