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());
    }
   }
  }

posted on 2007-10-07 13:36 浙林龙哥 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/huqingyu/archive/2007/10/07/916002.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值