Jdbc-mysql classic case and jdbc-mysql classic case
Package com.exe clExport. util; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. preparedStatement; import java. SQL. resultSet; import java. SQL. SQLException;/*** DatabaseUtil * created by: TanLiu * Time: 9:08:23 * function: */public class DatabaseUtil {private final String Driver = "com. mysql. jdbc. driver "; private final String URL =" jdbc: mysql: // localhost: 3306/tmdest "; private final String User = "root"; private final String pwd = "123456"; private Connection con = null; private PreparedStatement ps = null; public ResultSet rs = null;/*** function: obtain the connection to the database */public void getConnection () {try {Class. forName (Driver); con = DriverManager. getConnection (URL, User, pwd);} catch (ClassNotFoundException e) {e. printStackTrace ();} catch (SQLException e) {e. printStackTrace () ;}}/*** function: query data * @ pa Ram SQL * @ param arr * @ return returns a dataset rs */public ResultSet getQuery (String SQL, String [] arr) {getConnection (); try {ps = con. prepareStatement (SQL); if (arr! = Null & arr. length> 0) {for (int I = 0; I <arr. length; I ++) {ps. setString (I + 1, arr0000i00000000000000000000rs0000ps.exe cuteQuery ();} catch (SQLException e) {e. printStackTrace ();} return rs;}/*** function: used for database update operations * @ param SQL * @ param arr * @ return row */public int getUpdate (String SQL, String [] arr) {int row = 0; getConnection (); try {ps = con. prepareStatement (SQL); if (arr! = Null & arr. length> 0) {for (int I = 0; I <arr. length; I ++) {ps. setString (I + 1, arr0000i00000000000000000000row0000ps.exe cuteUpdate ();} catch (SQLException e) {e. printStackTrace ();} finally {this. closeAll ();} return row;}/*** function: Shut down the logstore operation */public void closeAll () {try {if (rs! = Null) {rs. close () ;}if (ps! = Null) {ps. close () ;}if (con! = Null) {con. close () ;}} catch (SQLException e) {e. printStackTrace ();}}}