java H2数据库使用并实现增删改查功能

java H2数据库使用并实现增删改查功能

package com.zuidaima.h2sql.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MainClass {

	/**
	 * @param args
         * @author www.zuidaima.com
	 */
	public static void main(String[] args) {
		Statement stmt = null;
		Connection conn = null;
		try {
			Class.forName("org.h2.Driver");
			conn = DriverManager.getConnection(
					"jdbc:h2:tcp://www.zuidaima.com:5435/mem:DBTest", "Guest",
					"123456");
			// add application code here
			stmt = conn.createStatement();
//			String createSql = "create table product(product_id integer not null,title varchar2(30) not null,type_id integer not null,info varchar2(80),price number(16,2) not null,constraint product_pk primary key (product_id),constraint product_fk foreign key(type_id) references item(type_id)))";
//			stmt.executeUpdate(createSql);
			// 添加一条语句
			// String insertSql =
			// "insert into UserInfo values('刘尚','www.zuidaima.com','888888','true',15827288756,15827288756)";
			// stmt.executeUpdate(insertSql);
			// 删除一条记录
			// String deleteSql = "delete from USERINFO where UID = '刘尚1'";
			// stmt.executeUpdate(deleteSql);
			// 修改一条语句
			// String UpdateSql =
			// "UPDATE USERINFO  SET IP='www.zuidaima.com' ,  LINKID='11111' , ACTION='FALSE' ,  UPTIME=2121231 ,DOWNTIME=2121212 WHERE UID='刘尚'";
			// stmt.executeUpdate(deleteSql);
			ResultSet rs = stmt.executeQuery("SELECT * FROM UserInfo ");
			 while (rs.next()) {
			 System.out.println("Uid:" + rs.getString("Uid") + "\tIp:"
			 + rs.getString("Ip") + "\tLinkId:"
			 + rs.getString("LinkId") + "\tAction:"
			 + rs.getBoolean("Action") + "\tUpTime:"
			 + rs.getLong("UpTime") + "\tDownTime:"
			 + rs.getLong("DownTime"));
			 }
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (stmt != null) {
					stmt.close();
					stmt = null;
				}
				if (conn != null) {
					conn.close();
					conn = null;
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}

标签: 数据库 H2 增删改查 CRUD java话题: 数据库相关 入门教程 Web开发

java H2数据库使用并实现增删改查功能,布布扣,bubuko.com

java H2数据库使用并实现增删改查功能

原文:http://blog.csdn.net/yaerfeng/article/details/38141653

上一篇:离开学校如何自学修炼成为一名网页设计师(二)


下一篇:tornado+ansible+twisted+mongodb运维自动化系统开发(三)