J'ai télé-chargé H2 database, mais je ne comprend pas trop son fonctionnement.
/* h2.jar must be in classpath */ import java.sql.*; import java.text.SimpleDateFormat; import java.util.Calendar; public class H2Demo { private Connection connection; private int bYear = 1949; private int bMonth = 9; private int bDate = 21; private Calendar cal = Calendar.getInstance(); public H2Demo() { try { try { Class.forName("org.h2.Driver"); System.out.println("out.h2.Driver"); connection = DriverManager.getConnection("jdbc:h2:~/test", "sa", ""); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } Statement stmt = connection.createStatement(); stmt.executeUpdate("CREATE TABLE if not exists customer(" + "First_Name char(50)," + "Last_Name char(50)," + "Birth_Date date)"); stmt.executeUpdate("delete from customer"); PreparedStatement pstmt = connection.prepareStatement("INSERT " + "INTO customer (First_Name, Last_Name, Birth_Date)" + "VALUES (?,?,?)"); int parameterIndex = 1; //First_Name: pstmt.setString(parameterIndex++, "Paul"); //Last_Name: pstmt.setString(parameterIndex++, "McCourt"); //Birth_Date: cal.set(Calendar.YEAR, bYear); cal.set(Calendar.MONTH, bMonth - 1); cal.set(Calendar.DATE, bDate); pstmt.setDate(parameterIndex++, new Date(cal.getTimeInMillis())); // pstmt.executeUpdate(); ResultSet rs = stmt.executeQuery("select * from customer"); while (rs.next()) { String firstname = rs.getString("First_Name"); String lastname = rs.getString("Last_Name"); Date birthdate = rs.getDate("Birth_Date"); java.util.Date date = new java.util.Date(birthdate.getTime()); SimpleDateFormat dfmt = new SimpleDateFormat("dd MMM yyyy"); System.out.println(firstname + " " + lastname + ", " + dfmt.format(date)); } rs.close(); stmt.close(); pstmt.close(); connection.close(); } catch (SQLException ex) { ex.printStackTrace(); } } public static void main(String[] args) { new H2Demo(); } }