mysql sqlserver 数据库

  • v3_953952
    了解作者
  • 35MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-09 02:28
    上传日期
对数据库的连接 复杂查询 sql语句应用技术 数据库高级应用
数据库应用.zip
内容介绍
package com.jwy.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; public class InboxDao { Connection con = null; public List findAll(){ List list = new ArrayList(); Statement st = null; ResultSet rs = null; try { con = DBConnection.getConnection(); //将连接设为只读模试 con.setReadOnly(true); st = con.createStatement(); rs = st.executeQuery("SELECT * FROM tb_inbox ORDER BY date desc"); while(rs.next()){ InboxDto mi = new InboxDto(); mi.setId(rs.getInt("id")); mi.setTitle(rs.getString("title")); mi.setContent(rs.getString("content")); mi.setDate(rs.getTimestamp("date").toString()); mi.setAddresser(rs.getString("addresser")); list.add(mi); } rs.close(); st.close(); } catch (SQLException ex) { ex.printStackTrace(); }finally{ try { con.close(); } catch (SQLException ex) { ex.printStackTrace(); }finally{ con = null; } } return list; } public void delete(String[] id){ PreparedStatement ps = null; try { con = DBConnection.getConnection(); //将事务提交方式设为手动提交方式 con.setAutoCommit(false); ps = con.prepareStatement("DELETE FROM tb_inbox WHERE id = ?"); for (int i = 0; i < id.length; i++) { //为ID参数赋值 ps.setInt(1, Integer.valueOf(id[i])); //将参数添加到PreparedStatement对象的批处理命令中 ps.addBatch(); } //将PreparedStatement对象中的全部命令一起提次给数据库来执行 ps.executeBatch(); //手动将提交事务 con.commit(); //关闭ps对象 ps.close(); } catch (Exception e) { try { //如果发生异常,将事务回滚 con.rollback(); } catch (SQLException ex) { ex.printStackTrace(); } e.printStackTrace(); }finally{ try { //关闭con对象 con.close(); } catch (SQLException ex) { ex.printStackTrace(); }finally{ //将con对象置空 con = null; } } } //将邮件从收件箱移动到垃圾箱 public void moveToCgbox(String[] id){ con = DBConnection.getConnection(); PreparedStatement ps = null; Statement st = null; ResultSet rs = null; try { con.setAutoCommit(false); st = con.createStatement(); ps = con.prepareStatement("SELECT * FROM tb_inbox WHERE id = ?"); for (int i = 0; i < id.length; i++) { ps.setInt(1, Integer.valueOf(id[i])); rs = ps.executeQuery(); rs.next(); st.addBatch("INSERT INTO tb_cgbox (title,content,date,addresser) values " + "('"+rs.getString("title")+"','"+rs.getString("content")+"','"+ rs.getTimestamp("date")+"','"+rs.getString("addresser")+"')"); st.addBatch("DELETE FROM tb_inbox WHERE id = " + id[i]); } st.executeBatch(); con.commit(); st.close(); rs.close(); ps.close(); } catch (Exception e) { try { con.rollback(); } catch (SQLException ex) { ex.printStackTrace(); } e.printStackTrace(); }finally{ try { con.close(); } catch (SQLException ex) { ex.printStackTrace(); }finally{ con = null; } } } }
评论
    相关推荐
    • sql server jdbc
      sql server jdbc 支持 Sqlserver 2000 sql server 2005 sql server 2008
    • sqlserver驱动
      sqlserver驱动jar包 sqlserver驱动jar包 sqlserver驱动jar包
    • SQLServer
      SQL Server PPT 课件
    • sqlserver数据包
      sqlserver数据包sqlserver数据包sqlserver数据包
    • sqlserver配置
      sqlserver配置sqlserver配置sqlserver配置sqlserver配置sqlserver配置sqlserver配置sqlserver配置sqlserver配置sqlserver配置sqlserver配置sqlserver配置sqlserver配置sqlserver配置sqlserver配置
    • SQLSERVER
      SQLSERVER的所有JAR包和文档说明
    • SQLServer
      SQLServer
    • SQLserver
      SQLserver
    • sql sqlserver 自动提示
      在安装vs2010 sp1 后sql无法代码自动提示,sql sqlserver自动提示
    • SQLSERVER
      SQL 基础理论知识,高级查询,