zoukankan      html  css  js  c++  java
  • 在Servlet中连接Access

     Connection conn = null;          
    Statement stmt = null;
    ResultSet rs = null;
    try{

    String MdbPath = new java.io.File(this.getServletContext().getRealPath("DBDemo.mdb")).getParent() + "\\DB\\DBDemo.mdb";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url= "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=" + MdbPath ;
    conn = DriverManager.getConnection(url);
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    } catch(SQLException e){
    log.error(e);
    } catch (ClassNotFoundException e) {

    e.printStackTrace();
    }



    String ID = request.getParameter("modId");

    try {
    rs = stmt.executeQuery("select * from template_file where templateID="+ID);
    while(rs.next()) {
    try {
    java.io.InputStream in = rs.getBinaryStream("filebody");
    java.io.OutputStream outStream = response.getOutputStream();
    byte[] buf = new byte[1024];
    int bytes = 0;
    while((bytes = in.read(buf)) != -1)
    outStream.write(buf, 0, bytes);
    in.close();
    outStream.close();
    }
    catch(Throwable e) {
    log.error(e);
    }
    }
    rs.close();
    stmt.close();
    conn.close();

    注意,不推荐使用request.getRealPaht()这个方法,会有问题。

  • 相关阅读:
    ios-pch文件的手动添加
    iOS远程消息推送自我整理版
    iOS远程消息推送
    苹果App store 2015最新审核标准公布(2015.3)
    App上线基本流程
    iOS中常用的正则表达式
    如何获取App当前版本号
    添加Appicon的方法
    键盘弹出
    iOS9适配中出现的一些常见问题
  • 原文地址:https://www.cnblogs.com/andgoo/p/2287574.html
Copyright © 2011-2022 走看看