Simple Database Gadget

Source: Internet
Author: User
Tags rollback create database

Package Henu.utils;import java.sql.*;p ublic class dbutil{/** * Declares information about connected databases, such as database URL, user name, and password */private static final String U RL = "Jdbc:mysql://localhost:3306/userdb"; private static final String USER = "root"; private static final String PASSWORD = "root"; /** * Declares the related object of JDBC */protected static Statement s = null; protected static ResultSet rs = null; protected static Connection conn = null; /** * CREATE DATABASE connection * @return Conn */public static synchronized Connectiono getconnection () {try{class.forname ("Com.mysql.jdbc. Driver "); conn = Drivermanager.getconnection (Url,user,password); }catch (Exception e) {e.printstacktrace ();} return conn; }/** * Executes insert\update\delete statement * @param SQL SQL statement, String type * @return execution result, int type */public static int executeupdate (String sql {int result = 0; try{s = getconnection (). createstatement (); result = S.executeupdate (sql);} catch (SQLException e) {e.printstacktrace ();} result result; /** * Execute SELECT statement * @param SQL SQL statement, String type * @return ResultSet result set */public static ResultSET executeupdate (String sql) {try{s = getconnection (). createstatement (); rs = s.executeupdate (sql);} catch (SQLException e) {e.printstacktrace ();} result rs; /** * Execute SQL statement * @param SQL Dynamic SQL statement with parameters * @return return preparedstaement Object */public static PreparedStatement EXECUTEPREPAREDST Atement (String sql) {PreparedStatement PS = null; try{PS = getconnection (). PreparedStatement (SQL);} catch (SQLException e) {e.printstacktrace ();} return PS; }/** * Transaction rollback */public static void rollback () {try{getconnection (). rollback (); catch (SQLException e) {e.printstacktrace ();}} /** * Close Database Connection object */public static void Close () {try{if (rs!=null) rs.close (); if (s!=null) s.close (); if (conn!=null) Conn.clo SE (); }catch (SQLException e) {e.printstacktrace ();}} }

Simple Database Gadget

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.