Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Running this course on an IDE

I downloaded the workspace and imported it into the IntelliJ IDEA. With workspaces, obviously you can just type the -cp to get the database imported to the project. How would you go about doing that in the IDE though?

4 Answers

Chris Ramacciotti
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Chris Ramacciotti
Treehouse Guest Teacher

Hi Shadd! You can definitely do this in an IDE. You'll just need to ensure that the SQLite JDBC library is on your classpath. You could do this by having the JAR in the project, then using your IDE to configure the project so that the JAR is included on the classpath. But, I'd say the quickest way would be to create a Gradle project in your IDE, and include the following in your build file:

dependencies {
    runtime 'org.xerial:sqlite-jdbc:3.8.11.2'
}

Notice that you only need to include it as a runtime (vs compile) dependency since you won't be using any of the library in your source code. After that, you can drop all the code written in the course into your main source directory, which is src/main/java if you've created a Gradle project using the defaults of the Gradle 'java' plugin (this is probably the case).

Then, you can use your IDE's Gradle tool window to build the project (which will download the SQLite dependency), and run your application.

Let me know if this works for you, and if not I can continue helping you troubleshoot!

So I shouldn't have to download any extra plugins? (I'm using the community edition)

ide

Alright so this is what I have after running the build. But I don't see any source files/folders. Do I have to create those?

Chris Ramacciotti
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Chris Ramacciotti
Treehouse Guest Teacher

Yep, that is correct - no additional plugins! I also use the IntelliJ Community Edition, even though I know Ultimate has tighter integration with a bunch of libraries. I just haven't found it to be necessary.

Awesome! I'll try out what you said and let you know how if I have any more questions. Thanks!!

Chris Ramacciotti
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Chris Ramacciotti
Treehouse Guest Teacher

Yep! You should be able to right-click on the root directory of the project, choose New > Directory, then enter "src/main/java". In there you can drop your source files, or create a package and place your source files there. Just be sure to update the package statement in the source files if you include a package and copy/paste the source from workspaces. :)

Still not working :(

Okay, I ran it and I'm still getting the CNFE. I've got the sqlite dependency listed, down there at the bottom. But it doesn't seem to know to pull from there. Is it just because where my files are? Do I need to move the gradle files into the src/main.java folder? Or is there something else I'm missing?

Also I should only have to run the build once, right? After it's built I only need to run the Main class.

I finally got it working. I don't know what I did to get it to work, but whatever I did was right. Lol. Thanks for the help!

In the course, you're going to output to a data file on your browser.

If you're going for a real database like MySQL or PostGRES, you'll need to define the location in your xml file under the connection url.

<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>

So basically the code he's writing only works to connect to a database through workspaces? Is that not possible to create locally in the IDE?