Complete CRUD operations on the database

Source: Internet
Author: User

PS: Query is relatively complex, to deal with the result set, adding and deleting Gerze not.

1  PackageIt.cast.jdbc;2 3 Importjava.sql.Connection;4 ImportJava.sql.ResultSet;5 Importjava.sql.SQLException;6 Importjava.sql.Statement;7 8  Public classCRUD {9 Ten     /** One      * @paramargs A      * @throwsclassnotfoundexception -      * @throwsSQLException -      */ the      Public Static voidMain (string[] args)throwsSQLException, ClassNotFoundException { - Delete (); -  -     } +      -     //Delete +     Static voidDelete ()throwsSQLException, ClassNotFoundException { A  atConnection conn =NULL; -Statement st =NULL; -ResultSet rs =NULL; -         //2. Establish a connection -conn =jdbcutils.getconnection (); -  in         //3. Create a statement -St =conn.createstatement (); to          +String sql = "Delete from user where name= ' name1 '"; -  the         //4. Execute the statement *         inti =st.executeupdate (SQL); $ Panax NotoginsengSystem.out.println ("i=" +i); -  the         //6. Releasing Resources + Jdbcutils.free (RS, St, conn); A     } the      +     //Modify -     Static voidUpdate ()throwsSQLException, ClassNotFoundException { $  $Connection conn =NULL; -Statement st =NULL; -ResultSet rs =NULL; the         //2. Establish a connection -conn =jdbcutils.getconnection ();Wuyi  the         //3. Create a statement -St =conn.createstatement (); Wu          -String sql = "Update user set MONEY=MONEY+10"; About  $         //4. Execute the statement -         inti =st.executeupdate (SQL); -  -System.out.println ("i=" +i); A  +         //6. Releasing Resources the Jdbcutils.free (RS, St, conn); -     } $  the  the     //New the     Static voidCreate ()throwsSQLException, ClassNotFoundException { the  -Connection conn =NULL; inStatement st =NULL; theResultSet rs =NULL; the         //2. Establish a connection Aboutconn =jdbcutils.getconnection (); the  the         //3. Create a statement theSt =conn.createstatement (); +          -String sql = "INSERT into user (Name,birthday,money) VALUES (' name1 ', ' 1997-01-01 ', 4000)"; the Bayi         //4. Execute the statement the         inti =st.executeupdate (SQL); the  -System.out.println ("i=" +i); -  the         //6. Releasing Resources the Jdbcutils.free (RS, St, conn); the     } the  -}
CRUD

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.