Java JDBC Database operations

Source: Internet
Author: User

1  PackageShb.java.demo3;2 3 ImportJava.sql.DriverManager;4 ImportJava.sql.ResultSet;5 Importjava.sql.SQLException;6 Importjava.sql.Statement;7 /**8 * JDBC Operations database9 * @Package: Com.cnpc.dlp.web.event.controllerTen * @Description: One  * @authorShihaobin A * @Date 2015-8-27 pm 1:31:15 -  */ -  Public classDemo12 { the      Public Static voidMain (string[] args) { -String url = "Jdbc:mysql://localhost:3306/base"; -String username = "root"; -String Password = "Bin"; +         Try { -             //Load Database driver +Class.forName ("Com.mysql.jdbc.Driver"); A}Catch(ClassNotFoundException e) { at             //TODO auto-generated Catch block - e.printstacktrace (); -         } -         Try { -             //getting and database connections -Java.sql.Connection connection=drivermanager.getconnection (URL, username, password); in             //To Create a query object -Statement Statement =connection.createstatement (); toString Sqlinsert = "INSERT INTO usertable (Username,password) VALUES (' Lizhe ', ' 923840298 ')"; +String sqlString = "Select username from usertable u where U.password = ' SDF '"; -             //Execute SQL statement the Statement.execute (sqlinsert); *SYSTEM.OUT.PRINTLN ("Success");  $ statement.close ();Panax Notoginseng connection.close (); -}Catch(SQLException e) { the             //TODO auto-generated Catch block + e.printstacktrace (); A         }  the          +     } -}

If there are errors please correct, thank you.

Java JDBC Database operations

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.