日期:2014-05-16  浏览次数:20404 次

jdbc连接access数据库
package com.core;
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 


public class Mytest {

	public static void main(String[] args) throws Exception { 
		Connection con=null ;
		 try {
		        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		        String filename = "F:/workspace/Demo5/src/com/core/aaa.mdb";
		        String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
		        database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end 
		        con = DriverManager.getConnection( database ,"","");
		        
		        
		    	
		    }
		 catch (Exception e) {
		        System.out.println("Error: " + e);
		    }
		 String sql =null;
	        for(int i=1;i<10;i++){
	        	sql = "insert into aaa(aa,bb) values ("+i+","+i+")";
	        	PreparedStatement pre = con.prepareStatement(sql); 
		 pre.executeUpdate();
		    	
	        } 
	        con.close();


	} 
}

?