java连接Access

public static Connection getDatabase() {
Connection con = null;
try {
//String addr=“D:\apache-tomcat-7.0.92\webapps\world”;
/Class.forName(“com.hxtt.sql.access.AccessDriver”);
String url = “jdbc:Access:///src//main//webapp//WEB-INF//qiege//demo.mdb”;
/
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
String url = “jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=src/main/webapp/WEB-INF/qiege/demo.mdb”;
con = DriverManager.getConnection(url,"","");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}

/**

  • 清空数据
    /
    public static void deleteShujun() {
    Connection con = getDatabase();
    CallableStatement ca1 = null;
    CallableStatement ca2 = null;
    CallableStatement ca3 = null;
    CallableStatement ca4 = null;
    CallableStatement ca5 = null;
    try {
    ca1 = con.prepareCall(“delete from Raws”);
    ca2 = con.prepareCall(“delete from Parts”);
    ca3 = con.prepareCall(“delete from Jobs”);
    ca4 = con.prepareCall(“delete from Cuts”);
    ca5 = con.prepareCall(“delete from Spaces”);
    int executeUpdate1 = ca1.executeUpdate();
    int executeUpdate2 = ca2.executeUpdate();
    int executeUpdate4 = ca4.executeUpdate();
    int executeUpdate5 = ca5.executeUpdate();
    int executeUpdate3 = ca3.executeUpdate();
    logger.info(“清空了库料”+executeUpdate1+“条数据”+",清空了需求料"+executeUpdate2+“条数据”+
    “,清空了作业”+executeUpdate3+“条数据”+",清空了需求料坐标"+executeUpdate4+“条数据”+",清空了余料"+executeUpdate5+“条数据”);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    if(ca1!=null) {
    try {
    ca1.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if(ca2!=null) {
    try {
    ca2.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if(ca3!=null) {
    try {
    ca3.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if(ca4!=null) {
    try {
    ca4.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if(ca5!=null) {
    try {
    ca5.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if(con!=null) {
    try {
    con.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }
    //获取数据
    public static List<Map<String, Object>> findSpaces() {
    List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
    Connection con = getDatabase();
    CallableStatement ca = null;
    ResultSet resultSet = null;
    try {
    ca = con.prepareCall("select s.
    ,j.RawIndex as rawIndex,j.Quantity as quantity from Spaces s left join Jobs j on s.FK=j.PK");
    resultSet = ca.executeQuery();
    while (resultSet.next()) {
    Map<String, Object> map = new HashMap<String, Object>();
    //map.containsKey(“11”);
    double liaoXsize = resultSet.getDouble(“Xsize”);
    double liaoYsize = resultSet.getDouble(“Ysize”);
    int rawIndex = resultSet.getInt(“rawIndex”);
    int quantity = resultSet.getInt(“quantity”);
    if(liaoXsize>10 && liaoYsize>10) {
    map.put(“liaox”, liaoXsize);
    map.put(“liaoy”, liaoYsize);
    map.put(“rawIndex”, rawIndex);
    map.put(“liaoq”, 1.00*quantity);
    list.add(map);
    //System.out.println(resultSet.getString(“Xsize”)+" , "+resultSet.getString(“Ysize”));
    logger.info(“余料x:”+liaoXsize+“余料y:”+liaoYsize+“数量:”+quantity);
    }
    }
    } catch (SQLException e) {
    e.printStackTrace();
    }
    if(resultSet!=null) {
    try {
    resultSet.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if(ca!=null) {
    try {
    ca.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if(con!=null) {
    try {
    con.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    return list;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值