jsp在mysql中删除数据_用jsp删除数据库中的记录怎么做?

这篇博客介绍了如何使用JSP连接到MySQL数据库并执行删除数据的操作。作者建议学习更高级的技术如Spring和Hibernate,以实现更方便、实用的数据管理。
摘要由CSDN通过智能技术生成

c0aa19f9f2a6ef6ef2d4802607476b77.png

2011-07-26

jsp连接数据库sqlserve

给你一个我很久以前写的,现在都已经不在使用这低级的用法了。建议你学学spring和hibernate,这个用起来更方便,实用。/** DataBaseConn。java** Created on 2006年1月26日, 上午10:19* 连接管理*/package ccb。 pub;import java。sql。*;import javax。sql。*;import ming。*;/**** @author*/public final class DataBaseConn {private static int iUsed = 0;/** Creat...全部

给你一个我很久以前写的,现在都已经不在使用这低级的用法了。建议你学学spring和hibernate,这个用起来更方便,实用。/* * DataBaseConn。java * * Created on 2006年1月26日, 上午10:19 * 连接管理 */package ccb。

pub;import java。sql。*;import javax。sql。*;import ming。*;/** * * @author */public final class DataBaseConn { private static int iUsed = 0; /** Creates a new instance of DataBaseConn */ private DataBaseConn() { } /* * 向数据库连接池申请一个数据连接 */ public static Connection getConn(){ Context ctx = null; DataSource ds = null; Connection cnn=null; String envString = tLinkPool(); try { ctx=new InitialContext(); if(ctx==null) throw new Exception("没有匹配的环境"); ds=(DataSource)ctx。

lookup(envString); if(ds==null) throw new Exception("没有匹配数据库"); cnn= tConnection(); //设置连接的事务提交方式均为自动提交 tAutoCommit(true); Debug。

logWithDetailByLevel("建立连接成功", 0, 2); iUsed++; StringBuffer msg = new StringBuffer(""); msg。

append("连接占用:"); msg。append(iUsed); Debug。logWithDetailByLevel( String(),0,2); }catch(Exception e) { Debug。

log(e); } return cnn; } /* * 将已经使用完毕的数据库连接返还给连接池 * 参数:conn 要返还的数据库连接 */ public static void closeConn(Connection conn){ if (conn != null){ try { ose(); Debug。

logWithDetailByLevel("断开连接成功", 0, 2); iUsed--; StringBuffer msg = new StringBuffer(""); msg。

append("连接占用:"); msg。append(iUsed); Debug。logWithDetailByLevel( String(),0,2); }catch(SQLException sqle){ Debug。

log(sqle); }finally{ conn = null; } } } }/* * DataBase。

java * * Created on 2005年12月13日, 下午6:04 * * 该类所在包为:ccb。pub。database,是一个公共类, * 为系统提供对SQL数据库连接功能。

* 使用时只需要构建这个类的实例对象就可。 */package ccb。pub;import java。sql。*;import ccb。pub。Consts;import ccb。

pub。Debug;import ccb。pub。DataBaseConn;/* * @author */public class DataBase { Connection conn = null; Statement stmt = null; ResultSet rs = null; public DataBase() { }/* * 执行sql插入语句 * 参数:sql:sql语句代码 * 返回:成功返回 Consts。

SUCC,否则为Consts。ERR_DB_OP */ public static int executeInsert(String sql) { Connection conntemp = null; Statement stmttemp = null; ResultSet rstemp = null; int ret_code = Consts。

SUCC; try { conntemp = tConn(); stmttemp = eateStatement(); stmttemp。

executeUpdate(sql); ose(); stmttemp = null; Debug。logWithDetailByLevel(sql, 1, 2); } catch (SQLException ex) { Debug。

log(ex); ret_code = Consts。ERR_DB_OP; }finally{ oseConn(conntemp); } return ret_code; } /* * 执行sql查询语句 * 参数:sql:sql语句代码 * 返回:成功返回 数据集,否则为 null * 注意:使用此函数将得到数据集,同时占用conn、stmt、rs等资源 * 使用此方法必须建立此类的实例 * 要求:使用完数据集后一定要调用closeConn方法释放占用资源 */ public ResultSet executeQuery(String sql) { int ret_code = Consts。

SUCC; try { if ((conn == null) ||( Closed())){ conn = tConn(); Debug。

logWithDetailByLevel("建立连接成功", 1, 2); } stmt = eateStatement( ResultSet。

TYPE_SCROLL_SENSITIVE, ResultSet。CONCUR_READ_ONLY); rs = null; rs = stmt。

executeQuery(sql); Debug。logWithDetailByLevel(sql, 1, 2); } catch (SQLException ex) { Debug。

log(ex); oseConn(conn); } return rs; } /* * 执行sql更新语句 * 参数:sql:sql语句代码 * 返回:成功返回 Consts。

SUCC,否则为Consts。ERR_DB_OP */ public static int executeUpdate(String sql) { Connection conntemp = null; Statement stmttemp = null; ResultSet rstemp = null; int ret_code = Consts。

SUCC; try { conntemp = tConn(); stmttemp = eateStatement(); stmttemp。

executeUpdate(sql); ose(); stmttemp = null; Debug。logWithDetailByLevel(sql, 1, 2); } catch (SQLException ex) { Debug。

log(ex); ret_code = Consts。ERR_DB_OP; }finally{ oseConn(conntemp); } return ret_code; } /* * 执行sql删除语句 * 参数:sql:sql语句代码 * 返回:成功返回 Consts。

SUCC,否则为Consts。ERR_DB_OP */ public static int executeDelete(String sql) { Connection conntemp = null; Statement stmttemp = null; ResultSet rstemp = null; int ret_code = Consts。

SUCC; try { conntemp = tConn(); stmttemp = eateStatement(); stmttemp。

executeUpdate(sql); ose(); stmttemp = null; Debug。logWithDetailByLevel(sql, 1, 2); } catch (SQLException ex) { Debug。

log(ex); ret_code = Consts。ERR_DB_OP; }finally{ oseConn(conntemp); } return ret_code; } /* * 释放由executeQuery方法建立的stmt资源 */ public void closeStmt(){ try{ if (stmt != null) ose(); }catch (SQLException sqle){ Debug。

log(sqle); }finally { stmt = null; } } /* * 释放由executeQuery方法建立的rs资源 */ public void closeResultSet(){ if (rs != null) { try{ ose(); }catch(SQLException sqle){ Debug。

log(sqle); } finally{ rs = null; } } } /* * 释放由executeQuery方法建立的conn资源 */ public void closeConn(){ if (conn != null){ try{ if (rs != null) ose(); if (stmt != null) ose(); oseConn(conn); Debug。

logWithDetailByLevel("断开连接成功", 1, 2); }catch(SQLException sqlw){ Debug。

log(sqlw); }finally{ rs = null; stmt = null; conn = null; } } }}public class Configure { static private int debug = 2; /** debug级别:1 只写异常 *      2 写数据库异常和文件操作异常 *      9 写全部信息 */ static private String logPath = "C:\\"; // 日志路径,缺省时为c:\log static private String logFileName = "System_Log。

Log"; // 日至文件名称 static private String upLoadPath = "upload"; //数据库库连接池名称 static private String linkpool = ""; //图片文件保存路径 static private String picpath = ""; /** Creates a new instance of Configure */ public Configure() { } /** * Getter for property debug。

* @return Value of property debug。 */ public static int getDebug() { return debug; } /** * Setter for property debug。

* @param debug New value of property debug。 */ public static void setDebug(int level) { if (level > 2){ debug = 2; }else{ debug = level; } } /** * Getter for property logPath。

* @return Value of property logPath。 */ public static String getLogPath() { return logPath; } /** * Setter for property logPath。

* @param logPath New value of property logPath。 */ public static void setLogPath(String LogPath) { if ((LogPath == null)||(LogPath。

equals(""))){ LogPath = "C:\\"; } if(!LogPath。endsWith("\\")){ StringBuffer lp = new StringBuffer(LogPath); lp。

append("\\"); LogPath = String(); } //测试路径的正确性 File dir = new File(LogPath); //如果路径不存在,在建立此路经 if((!dir。

exists())||(! Directory())){ if(! dirs()){ //建立目录失败,就在C:\目录下建立日志文件 LogPath = "C:\\"; intln("建立日志路径失败,请联系系统管理员。

"); } } logPath = LogPath; } /** * Getter for property logFileName。

* @return Value of property logFileName。 */ public static String getLogFileName() { return logFileName; } /** * Setter for property logFileName。

* @param logFileName New value of property logFileName。 */ public static void setLogFileName(String LogFileName) { if((LogFileName == null)||(LogFileName。

equals(""))){ LogFileName = "System_Log。Log"; } //判断扩展名正确性 LogFileName = UpperCase(); if(!LogFileName。

endsWith("。LOG")){ StringBuffer lf = new StringBuffer(LogFileName); lf。

append("。LOG"); LogFileName = String(); } logFileName = LogFileName; } /* * 从xml文件中读取相关配置信息 * 参数:xmlfilename 配置文件的文件名称, 文件为xml格式 */ public static void loadConfigureFromXML(String xmlfilename){ //建立xml解析类实例 DocumentBuilderFactory dbf = wInstance(); DocumentBuilder db = null; try { db = wDocumentBuilder(); } catch (ParserConfigurationException pce) { intln(pce); //出异常时输出异常信息,不修改任何环境信息 } //建立文档读写类实例 //如果发生任何异常,将不修改系统信息,使用原有设置建立日志文件 Document doc = null; try { doc = rse(xmlfilename); }catch(SAXException saxe){ intln( tMessage()); return; } catch (DOMException dom) { intln( tMessage()); return ; } catch (IOException ioe) { intln( tMessage()); return; } //获取xml文件的根信息 Element root = tDocumentElement(); //获取日志路径 NodeList configs = tElementsByTagName("logpath"); Element config = (Element) em(0); Text t = (Text) tFirstChild(); String logpath = tNodeValue(); //获取日至文件名称 configs = tElementsByTagName("logfilename"); config = (Element) em(0); t = (Text) tFirstChild(); String logfilename = tNodeValue(); //获取debug级别信息 configs = tElementsByTagName("debug"); config = (Element) em(0); t = (Text) tFirstChild(); String debuglevelstr = tNodeValue(); int debuglevel = rseInt(debuglevelstr); //设置系统参数 setDebug(debuglevel); setLogPath(logpath); setLogFileName(logfilename); } /* * 通过debug、logpath、logfilename参数建立配置类实例 * */ public Configure(int debuglevel,String logpath,String logfilename){ setDebug(debuglevel); setLogPath(logpath); setLogFileName(logfilename); } /* * 设置上传文件目录 * 参数:上传文件目录 */ public static void setUpLoadPath(String uploadpath){ if ((uploadpath == null)||(uploadpath。

equals(""))){ uploadpath = "C:\\"; } if(!uploadpath。endsWith("\\")){ StringBuffer lp = new StringBuffer(uploadpath); lp。

append("\\"); uploadpath = String(); } //测试路径的正确性 File dir = new File(uploadpath); //如果路径不存在,在建立此路经 if((!dir。

exists())||(! Directory())){ if(! dirs()){ //建立目录失败,就在C:\目录下建立日志文件 uploadpath = "C:\\"; intln("建立上传文件路径失败,请联系系统管理员。

"); } } upLoadPath = uploadpath; } /* * 获取上传文件目录 * */ public static String getUpLoadPath(){ return upLoadPath; } /**功能:设置数据库连接池的名称 * 参数:数据库连接名称 * 返回:无 */ public static void setLinkPool(String strLinkPool){ linkpool = strLinkPool; } /**功能:获取数据库连接池名称 * 参数:无 * 返回:数据库连接赤名称 */ public static String getLinkPool(){ return linkpool; } /**功能:设置图片文件保存目录 *参数:picpath *返回:无 */ public static void setPicPath(String PicPath){ picpath = PicPath; } /**功能:获取图片文件保存目录 *参数: *返回:文件路径 */ public static String setPicPath(){ return picpath ; } 。

收起

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值