Package cn.com. JDBC; import java. SQL. connection; import java. SQL. resultSet; import java. SQL. SQLException; import java. SQL. statement; public class CRUD {public static void main (String [] args) throws SQLException {// TODO Auto-generated method stub // create (); // update (); delete (); read () ;}static void delete () throws SQLException {Connection conn = null; Statement st = null; ResultSet resultset = null; try {// 2. establish connection con N = JdbcUtils. getConnection (); // Singleton design mode conn = JdbcUtilsSingle. getInstance (). getConnection (); // 3. create statement st = conn. createStatement (); // 4. execute the statement String SQL = "delete from user where id> 5"; int imo-st.exe cuteUpdate (SQL); System. out. println ("I =" + I);} finally {JdbcUtils. free (resultset, st, conn) ;}} static void update () throws SQLException {Connection conn = null; Statement st = null; ResultSet resultset = null; try {// 2. establish connection conn = Jdbc Utils. getConnection (); // Singleton design mode conn = JdbcUtilsSingle. getInstance (). getConnection (); // 3. create statement st = conn. createStatement (); // 4. execute the statement String SQL = "update user set money = money + 20"; int imo-st.exe cuteUpdate (SQL); System. out. println ("I =" + I);} finally {JdbcUtils. free (resultset, st, conn) ;}} static void create () throws SQLException {Connection conn = null; Statement st = null; ResultSet resultset = null; try {// 2. establish connection conn = JdbcUti Ls. getConnection (); // Singleton design mode conn = JdbcUtilsSingle. getInstance (). getConnection (); // 3. create statement st = conn. createStatement (); // 4. execute the statement String SQL = "insert into user (name, birthday, money) values ('wy', '2017-09-23 ', '123 ')"; int iw.st.exe cuteUpdate (SQL); System. out. println ("I =" + I);} finally {JdbcUtils. free (resultset, st, conn) ;}} static void read () throws SQLException {Connection conn = null; Statement st = null; ResultSet re Sultset = null; try {// 2. establish connection conn = JdbcUtils. getConnection (); // Singleton design mode conn = JdbcUtilsSingle. getInstance (). getConnection (); // 3. create statement st = conn. createStatement (); // 4.execute the sentence resultset=st.exe cuteQuery ("select id, name, birthday, money from user"); // 5. processing result while (resultset. next () {System. out. println (resultset. getObject ("id"); System. out. println (resultset. getObject ("name"); System. out. println (resultset. getObject ("birthda Y "); System. out. println (resultset. getObject ("money") ;}} finally {JdbcUtils. free (resultset, st, conn) ;}} package cn.com. JDBC; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. resultSet; import java. SQL. SQLException; import java. SQL. statement; public class JdbcUtils {private static String url = "jdbc: mysql: // localhost: 3306/jdbc"; private static String user = "root"; private static Stri Ng password = "123"; private JdbcUtils () {} static {try {Class. forName ("com. mysql. jdbc. driver ");} catch (ClassNotFoundException e) {throw new ExceptionInInitializerError (e) ;}} public static Connection getConnection () throws SQLException {return DriverManager. getConnection (url, user, password);} public static void free (ResultSet resultset, Statement st, Connection conn) {// 6. release resource try {if (resultset! = Null) resultset. close ();} catch (SQLException e) {// TODO Auto-generated catch blocke. printStackTrace ();} finally {try {if (st! = Null) st. close ();} catch (SQLException e) {// TODO Auto-generated catch blocke. printStackTrace ();} finally {if (conn! = Null) try {conn. close ();} catch (SQLException e) {// TODO Auto-generated catch blocke. printStackTrace ();}}}}}