Posted By

jerryvig on 03/03/12


Tagged

database java start tcp in memory h2


Versions (?)

Start H2 In Memory Database


 / Published in: Java
 

This Java program is used to start an H2 in memory (RAM) database (http://www.h2database.com) and start a tcp server so that other processes can read and write data to the in memory database through a TCP connection.

  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.Statement;
  4. import java.sql.Connection;
  5. import java.sql.SQLException;
  6. import org.h2.tools.Server;
  7.  
  8. public class StartH2Morningstar {
  9. public static void main( String[] args ) {
  10. try {
  11. Class.forName("org.h2.Driver");
  12. } catch ( ClassNotFoundException cnfe ) { cnfe.printStackTrace(); }
  13.  
  14. try {
  15. Connection conn = DriverManager.getConnection("jdbc:h2:mem:delicious","sa","");
  16. Statement stmt = conn.createStatement();
  17. stmt.executeUpdate("CREATE TABLE test_table( test_val VARCHAR(10) )");
  18.  
  19. Server server = Server.createTcpServer().start();
  20. }
  21. catch ( SQLException sqle ) { sqle.printStackTrace(); }
  22. }
  23. }

Report this snippet  

You need to login to post a comment.