Original: Java H2 database use and implementation of additions and deletions to change function code: http://www.zuidaima.com/share/1550463278058496.htm
Java H2 Database use and implementation of additions and deletions to change the function
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.zu idaima.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 HERESTMT = Conn.createstatement ();// String createsql = "CREATE TABLE Product" (product_id integer Not Null,title varchar2 (no) null,type_id integer NOT NULL, Info VARCHAR2, price number (16,2) is not null,constraint PRODUCT_PK primary key (product_id), constraint PRODUCT_FK Foreign KEY (type_id) references item (TYPE_ID)) ";//stmt.executeupdate (createsql);//Add a statement//String insertsql =//" INSERT into UserInfo values (' Astrologer ', ' www.zuidaima.com ', ' 888888 ', ' true ', 15827288756,15827288756) "// Stmt.executeupdate(insertsql);//delete a record//String deletesql = "Delete from USERINFO where UID = ' astrologer 1 '";//Stmt.executeupdate (DELETESQL);//Modify One statement//String updatesql =//"UPDATE USERINFO SET ip= ' www.zuidaima.com ', linkid= ' 11111 ', action= ' FALSE ', uptime=21212 downtime=2121212 where uid= ' astrologer ' ";//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.gets Tring ("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 Blocke.printstacktrace ();}}}
label: database H2 additions and deletions crud java topic: Database related Getting Started tutorial web development