1.首先把h2-1.3.174.jar 文件引用到项目中 右键--属性---java构建路径---库---添加外部jar文件
import java.awt.Button;
import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import org.h2.Driver;
public class helloworld {
/**
* @param args * @throws ClassNotFoundException * @throws SQLException */ public static void main(String[] args) throws ClassNotFoundException, SQLException { // TODO Auto-generated method stub System.out.println("Hello World!"); Class.forName("org.h2.Driver"); Connection conn = DriverManager. getConnection("jdbc:h2:tcp://192.168.1.246/~/test", "sa", ""); ResultSet rs1 = conn.createStatement().executeQuery("select name from TEST"); // 事务中读 rs1.next(); rs1.next(); String ss=String.valueOf(rs1.getString(1)); System.out.println(ss); conn.close(); // add application code here } }