Jdbc-mysql classic case and jdbc-mysql classic case

Source: Internet
Author: User

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 ();}}}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.