zoukankan      html  css  js  c++  java
  • java连接access数据库简单demo

    用户java访问access2007 不需要配置数据源!


    public static void main(String[] args) throws SQLException, UnsupportedEncodingException {
    		// --Access 数据库路径
    		String dbpath = "C:\\Users\\hlu\\Desktop\\hua\\hua_dic_db.mdb";   //路劲最好不要出现中文,本人测试过程中中文报错!
    		// --连接字符串
    		String url = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="
    				+ dbpath;
    		Properties properties = new Properties() ;
    		properties.setProperty("charSet", "gbk") ;			//这里设置是为了防止查询的时候出现乱码
    		Connection conn = null;
    		try {
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		}
    		conn = DriverManager.getConnection(url,properties);
    		Statement statement = conn.createStatement();
    		ResultSet rs = statement.executeQuery("select * from xhzd_surnfu");
    		while(rs.next()){
    			System.out.println(new String(rs.getString(1).getBytes(),"UTF-8")) ;	//1.查询的时候下标是从1开始的;2. 注意转编码
    		}
    		conn.close();
    	}




  • 相关阅读:
    Kubernetes 部署Mysql 主从复制集群
    Kubernetes Kube-proxy
    vRO Extend VirtualDisk Workflow
    Kubernetes Horizontal Pod Autoscaler
    vRO 7 添加RestHost证书报错
    Kubernetes Resource Qoutas
    Kubernetes 命令补全
    Kubernetes 部署Weave Scope监控
    Kubernetes Yaml
    Go reflect反射
  • 原文地址:https://www.cnblogs.com/java20130722/p/3207297.html
Copyright © 2011-2022 走看看