Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Hibernate Basics Data Persistence & ORMs Using JDBC to Connect to a Database

Dave Goodchild
Dave Goodchild
1,141 Points

Doesn't seem to be establishing a connection, or something is up with the backend service that tries to execute the code

The following code just never

// Load class "org.sqlite.JDBC" Class.forName("org.sqlite.JDBC");

// Establish connection to database named "treehouse.db" try(Connection c = DriverManager.getConnection("jdbc:sqlite:treehouse.db")) {

} catch(SQLException ex) {

}

Application.java
// Load class "org.sqlite.JDBC"
Class.forName("org.sqlite.JDBC");

// Establish connection to database named "treehouse.db"
try(Connection c = DriverManager.getConnection("jdbc:sqlite:treehouse.db")) {

} catch(SQLException ex) {

}

3 Answers

Dave Goodchild
Dave Goodchild
1,141 Points

You can see some examples of "try with resources" here: https://blogs.oracle.com/weblogicserver/using-try-with-resources-with-jdbc-objects

The problem is the Treehouse error that states: "Oh no! We didn't hear from the challenge service in a timely fashion!".

I've reported it to their support team. But in case anyone else comes by, the construct is valid and I'll report back here what they reply with.

Dave Goodchild
Dave Goodchild
1,141 Points

The support team came back to inform me that there had been technical difficulties and that they were resolved by end of the day.

John Lack-Wilson
John Lack-Wilson
8,169 Points

Hey Dave, thanks for the question - the problem here is that try / catch blocks should look like this below:

try {
    // Your code here - i.e. what you want to try to do
} catch (Exception exc) {
    // Error handling code
}

I understand the way that the challenge has been set out makes it seem like you put your code within the try ( here), but try keyword should be followed by an opening curly brace.

Dave Goodchild
Dave Goodchild
1,141 Points

This construct is a "try with resources", the issue seems to be the actual connection is timing out and I'm receiving an error about the server process not executing in time.

John Lack-Wilson
John Lack-Wilson
8,169 Points

Fair enough, but it did work for me when I put your code inside the try block.