zoukankan      html  css  js  c++  java
  • Java向Access插入数据

    Connection conn = null;
      Statement stmt1 = null;

      System.out.println("Start write access...");
      try {
       String strurl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=abc.mdb";
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //驱动程序
       conn = DriverManager.getConnection(strurl); //建立连接对象
       
       stmt1 = conn.createStatement();
       
       System.out.println("append records:");
       String sql = "insert into Table_A (Id,Description) values (504,?)";
      
       PreparedStatement ps = conn.prepareStatement(sql);
       ps.setString(1,"vvv");
       ps.executeUpdate();
       
       System.out.println("success.");
      }
      catch(ClassNotFoundException cnfe)
      {
       System.out.println("error:" + cnfe.getMessage());
      }
      catch(SQLException sqlExp)
      {
       System.out.println("error:" + sqlExp.getMessage());
      }
      catch(Exception e)
      {
       System.out.println("error:" + e.getMessage());
      }
      finally
      {
       if(stmt1 != null)
       {
        try
        {
         stmt1.close();
        }
        catch(Exception e)
        {
         System.out.println("error:" + e.getMessage());
        }
       }

       if(conn != null)
       {
        try
        {
        conn.close();
        }
        catch(Exception e)
        {
         System.out.println("error:" + e.getMessage());
        }
       }
      }

  • 相关阅读:
    区分JS的空值
    死锁
    高效的SQLSERVER分页方案
    IIS经典模式VS集成模式
    MVC过滤器
    Request接收参数乱码原理解析
    int三种转化区别
    Area使用
    Action和Partial等区别
    Log4Net
  • 原文地址:https://www.cnblogs.com/huqingyu/p/916002.html
Copyright © 2011-2022 走看看