欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java h2内存模式,javah2内存,java程序中使用h2的

来源: javaer 分享于  点击 4839 次 点评:4

java h2内存模式,javah2内存,java程序中使用h2的


java程序中使用h2的内存模式,并启动一个tcp server接受其他进程通过tcp连接读取此jvm中h2数据库的内容。

import java.sql.Connection;import java.sql.DriverManager;import java.sql.Statement;import java.sql.Connection;import java.sql.SQLException;import org.h2.tools.Server;public class StartH2Morningstar {  public static void main( String[] args )  {    try {       Class.forName("org.h2.Driver");    } catch ( ClassNotFoundException cnfe ) { cnfe.printStackTrace(); }    try {      Connection conn = DriverManager.getConnection("jdbc:h2:mem:delicious","sa","");      Statement stmt = conn.createStatement();      stmt.executeUpdate("CREATE TABLE test_table( test_val VARCHAR(10) )");      Server server = Server.createTcpServer().start();    }    catch ( SQLException sqle ) { sqle.printStackTrace(); }  }}
相关栏目:

用户点评