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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Ly Nguyen](https://uploads.teamtreehouse.com/production/profile-photos/4848192/micro_Me_Profile_Picture.jpg)
Ly Nguyen
8,749 PointsHow do you create a statement and execute a query using Java and SQL?
I believe I am following the right steps but the compiler says that it cannot find the symbol.
// Load class "org.sqlite.JDBC"
// Establish connection to database named "treehouse.db"
try(Connection c = DriverManager.getConnection("jdbc:sqlite:treehouse.db")) {
Class.forName("org.sqlite.JDBC");
Statement stmt = null;
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("INSERT INTO languages (id, name) VALUES (2, 'Java')");
} catch(SQLException ex) {
}
Ly Nguyen
8,749 PointsLy Nguyen
8,749 PointsI was able to figure out my mistake. I should have run the executeUpdate method instead of executeQuery method. Also, there is no ResultSet created if you're not querying.
New code that passes: