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

data base not getting created on workspace with the java code as shown in hibernate 2nd lecture

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;

import java.util.List; import java.util.ArrayList;

public class JdbcMain { public static void main(String[] args) throws ClassNotFoundException { // TODO: Load the SQLite JDBC driver (JDBC class implements java.sql.Driver) Class.forName("org.sqlite.JDBC");

// TODO: Create a DB connection
try(Connection connection = DriverManager.getConnection("jdbc:sqlite:contactmgr.db")) {

  // TODO: Create a SQL statement
  Statement statement = connection.createStatement();

  // TODO: Create a DB table
  statement.executeUpdate("DROP TABLE IF EXISTS contacts");
  statement.executeUpdate("CREATE TABLE contacts(id INTEGER PRIMARY KEY,firstname STRING ,lastname STRING,email STRING,phone INT(10))");


  // TODO: Insert a couple contacts
  statement.executeUpdate("INSERT INTO contacts(firstname,lastname,email,phone)
                           VALUES('SACHIT','KORGAONKAR','sachit.korgaonkar@yahoo.com',9503820832)");
  // TODO: Fetch all the records from the contacts table
  ResultSet rs =statment.executeQuery("SELECT * FROM contacts");
  // TODO: Iterate over the ResultSet & display contact info
  while(rs.next()){
  int id =rs.getInt("id");
    String firstname =rs.getString("firstname");
  String last =rs.getString("lastname");
    System.out.printf("%s %s (%d)",firstname.lastname.id);
  }
} catch (SQLException ex) {
  // Display connection or query errors
  System.err.printf("There was a database error: %s%n",ex.getMessage());
}

} }