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 trialMartin Batista
4,606 PointsI'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')");
// 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
23,733 PointsYou need to create a Statement and call executeUpdate on that.
Akhter Rasool
8,597 PointsAfter 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
4,606 PointsI see my mistake now.
Thank you very much!
Martin Batista
4,606 PointsMartin Batista
4,606 PointsThank you very much!