access数据库连接方法

加粗样式

	这个是比较老点的数据库,此文章就是为了新手不调入坑中
		这个是Java代码
		package com.demo.utils;

import java.sql.*;

public class Test4 {

public static void main(String[] args) {
// TODO Auto-generated method stub

//定义需要的对象
PreparedStatement ps=null;
Connection ct=null;
ResultSet rs=null;

int count=1;

try {

Class.forName(“com.hxtt.sql.access.AccessDriver”);
ct=DriverManager.getConnection(“jdbc:Access:/E:ProductRecord.mdb”);

//创建ps,创建数据库
ps=ct.prepareStatement(“select * from Material where id=1”);
rs=ps.executeQuery();
while(rs.next())
{
System.out.println(rs.getInt(1)+" “+rs.getString(2)+” “+rs.getString(3)+” “+rs.getString(4)+” "+rs.getString(5));
count++;
}
System.out.println(“总行数”+count);

} catch (Exception e) {
e.printStackTrace();
}finally {
//关闭资源!!!!!
try {
if(ps!=null)
{
ps.close();
}
if(ct!=null)
{
ct.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}

}

}

}

1.这个项目是本人亲测有效的上面那个是我从老前辈那里得到的
2.此项目还有一个jar包
这个是连接jdbc-odbc的 我把这个下载地址放在我的百度云里面
这个是我的联系方式有需求的请联系qq: 1302943546

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值