Studyon Minte9.com
Jdbc




H2



Put the h2.jar file on extensions folder

C:Program Files/Java/jdk1.6.0_37/jre/lib/ext/
H2 datafiles are located in user directory
C:/Documents and Settings/username/test.data.db (test.trace.db, etc ...)
When moving data/ directory to another computer you must first delete the old one. Only copy/replace data/ will not work.
package testexample; import javax.swing.*; import java.sql.*; public class Test extends JFrame { public static void main(String[] args) throws Exception { Class.forName("org.h2.Driver"); Connection con = DriverManager.getConnection("jdbc:h2:~/test", "test", "" ); Statement stmt = con.createStatement(); stmt.executeUpdate( "DROP TABLE teams" ); stmt.executeUpdate( "CREATE TABLE teams ( name varchar(50) )" ); stmt.executeUpdate( "INSERT INTO teams ( name ) VALUES ( 'Fiorentina' )" ); stmt.executeUpdate( "INSERT INTO teams ( name ) VALUES ( 'Juventus' )" ); ResultSet rs = stmt.executeQuery("SELECT * FROM teams"); while( rs.next() ) { System.out.println(rs.getString("name")); } // Outputs: Fiorentina, Juventus stmt.close(); con.close(); } }
  H2 to be contain in the jar file: (see ... Netreans / App embeded jar) 1) Netbeans / testexample / Libraries > add JAR/Folder (h2.jar) 2) Neatbeans, switch to file model, change build.xml 3) build.xml (right click) Run Target Other Targets -> package-for-store D:developmentstestexamplestore ... testexample.jar


http://studyon.minte9.com/article/useraccount/show/id/1012
http://www.claudiobernasconi.ch/2010/08/17/h2-embedded-java-db-getting-started
http://www.java2s.com/Code/Jar/h/Downloadh2jar.htm