我要访问访问本地的access数据库,要用jdbc吧,不是很熟悉,不知道具体怎么应用,不知道有没有例子?谢谢
解决方案 »
- 【请大家讨论】火车站票务管理系统的业务逻辑。。。
- 对writeUTF()方法的疑惑
- 画同心圆不同心问题
- 奇怪!!!jdk5的doc里没有AbstractStringBuider这个类?谁能给各解释!!!
- 问一个超级简单的基础java问题,我想访问protected修饰的方法,应该怎么访问呢
- think in java上说的“名字隐藏”是什么意思?
- 高手指教:怎么读取一个PDF文件中的文本啊?
- 一个有关继承的问题!!!
- 请赐教:关于Java于Access数据库操作的问题
- 请问Netty适合做HTTP服务容器吗?
- 请问下用DELPHI和JAVA做一个C/S的小的管理信息系统谁更麻烦点,谢谢
- readLine()与readInt()用法上有什么区别
搜索java连接access
private static String url="";
private String driver="";
private String uname="";
private String pwd="";
private static String sql="";
private static Connection con=null;
private static Statement stm=null;
private static ResultSet rs=null;
public Sun() throws Exception{
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:数据库名字";
sql="select * from admin";
classForName(driver);
}
public static void classForName(String driver){
try{
Class.forName(driver);
}
catch(Exception e){
System.out.print(e.getMessage());
}
}
public static Connection getConnection(){
try{
con=DriverManager.getConnection(url);
}
catch(Exception e){
System.out.print(e.getMessage());
}
return con;
}
public static Statement getStatement(){
try{
stm=getConnection().createStatement();
}
catch(Exception e){
System.out.print(e.getMessage());
}
return stm;
}
public static ResultSet executeQuery(String sql){
try{
rs=getStatement().executeQuery(sql);
}
catch(Exception e){
System.out.print(e.getMessage());
}
return rs;
}
public static int executeUp(String sql){
int i=0;
try{
i=getStatement().executeUpdate(sql);
System.out.println(i);
}
catch(Exception e){
System.out.print(e.getMessage());
}
return i;
} public static void closeAll() throws Exception{
if(stm!=null){
stm.close();
System.out.println("stm");
}
if(con!=null){
if(!con.isClosed()){
con.close();
System.out.println("con!");
}
}
}
public static void main(String args[]) throws Exception{
try{
Sun s=new Sun();
/*
rs=executeQuery(sql);
while(rs.next()){
System.out.print(rs.getString("pwd"));
}
rs.close();*/
sql="insert into admin(pwd) values('aaa')";
executeUp(sql);
closeAll();
}
catch(Exception e){
System.out.print(e.getMessage());
}
finally{
}
}
}
还有 如何设置相对的路径呢 比如在一个和系统集成在同一个目录中