dbmanager.java

来自「一个常用的电子商城的站点源码」· Java 代码 · 共 74 行

JAVA
74
字号
package com.publish.shop.util.db;import java.sql.*;import com.publish.shop.util.javabeans.Debug;import com.publish.shop.util.javabeans.ShopException;public class DbManager{  /**   * @param sql   * @return int   * @throws PmmvsException   */  public static int executeUpdate(String sql) throws Exception  {    Debug.println("update,delete,insert: "+sql);    int rs = 0;    Connection con = null;    Statement stmt = null;    try    {      con = DbPool.getConnection();      stmt = con.createStatement();      rs = stmt.executeUpdate(sql);      con.commit();    }    catch(Exception sqlEx)    {      throw sqlEx;    }    finally    {      DbPool.closeStatement(stmt);      DbPool.closeConnection(con);    }    return rs;  }  /**   * @param sql   * @return int   * @throws PmmvsException   */  public static int executeUpdate(Connection con, String sql) throws Exception  {    Debug.println("update: " + sql);    int rs = 0;    Statement stmt = null;    try    {      stmt = con.createStatement();      rs = stmt.executeUpdate(sql);    }    catch(Exception sqlEx)    {      throw sqlEx;    }    finally    {      DbPool.closeStatement(stmt);    }    return rs;  }  public static String replaceString(String str)  {    if (str!=null && str.length()>0)    {      str = str.replace('*', '&');      str = str.replace('?', '-');    }    return str;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?