Java H2 Database use and implementation of additions and deletions to change the function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.