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