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 JDBC to Connect to a Database

Martin Batista
Martin Batista
4,606 Points

I'm getting syntax error and I can't find it. Please point me in the right direction

c.executeUpdate("INSERT INTO languages(id,name)VALUES(2,'Java')");

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")) {

  c.executeUpdate("INSERT INTO languages(id,name)VALUES(2,'Java')");

} catch(SQLException ex) {

}

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

You need to create a Statement and call executeUpdate on that.

Akhter Rasool
Akhter Rasool
8,597 Points

After the first statement in the try block insert a ';' and then next line you must create a statement in the following manner:

Statement statement (equals) c.createStatement();

this creates a statement where this statement can hold a sql statement and execute that very query.

so the way you execute your sql query is like this:

statement(dot)executeUpdate("INSERT INTO languages(id,name)VALUES(2,'Java')");

Martin Batista
Martin Batista
4,606 Points

I see my mistake now.

Thank you very much!