Cache数据库驱动及其JAVA代码demo

  • Post author:
  • Post category:java

jar包下载—阿里云盘地址如下:

cache-jdbc-2.0.0.jar

https://www.aliyundrive.com/s/GjFrQqL5hkV
提取码: 15yc 

java代码如下:

try {
            // Create special Cache object
            CacheDataSource ds = new CacheDataSource();
            // Connection parameters

            ds.setURL("jdbc:Cache:127.0.0.1:19722/dhc-app");
            ds.setUser("admin");
            ds.setPassword("abc123");
            Connection dbconnection = ds.getConnection();
            Statement stmt = dbconnection.createStatement();
            StringBuffer stringBuffer = new StringBuffer();
			//查询SQL拼接,根据自己的要求处理
            stringBuffer.append("SELECT * FROM  Nur_OutInterface_Labor.FindDelivery(\"").append("332572").append("\")");
			//查询结果
            ResultSet rs = stmt.executeQuery(stringBuffer.toString());
            ArrayList<String> arrayList = new ArrayList<>();
			//查看当前SQL有多少数据字段
            int columnCount = rs.getMetaData().getColumnCount();
            for (int i = 1; i <= columnCount; i++) {
				//保存所有的数据字段
                String columnName = rs.getMetaData().getColumnName(i);
                arrayList.add(columnName);
            }
			// 自行处理
            HashMap<String, Object> dataMap = new HashMap<String, Object>();
            list = new ArrayList<Map<String, Object>>();
            while (rs.next()) {
                for (String s : arrayList) {
                    dataMap.put(s.split("_")[1], rs.getString(s));
                }
                list.add(dataMap);
            }
            rs.close();
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }


版权声明:本文为zf199805原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。