java代码如下:
package com.rsr.test;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import java.util.ArrayList;import java.util.List;public class allStaffTest { public static void main(String[] args) { String driver="com.mysql.jdbc.Driver";//驱动路径 String url="jdbc:mysql://192.168.1.128:3306/rsrmsg";//数据库地址 String user="root";//访问数据库的用户名 String password="rsr_dev";//用户密码 try { //1、加载驱动 Class.forName(driver); //2、链接数据库 Connection con = DriverManager.getConnection(url, user, password); Listlist = new ArrayList (); if(!con.isClosed()){//判断数据库是否链接成功 System.out.println("已成功链接数据库!"); //3、创建Statement对象 Statement st = con.createStatement(); //4、执行sql语句 String sql="SELECT a.id as aId,a.name as aName,b.hukou_type as aHukou,b.fund_all_c as aFundc,b.fund_all_p as aFundp from base b LEFT JOIN area a on a.id = b.area_id where fund_all_c is not null";//查询user表的所有信息 ResultSet rs = st.executeQuery(sql);//查询之后返回结果集 //5、打印出结果 while(rs.next()){// List allList = new ArrayList (); String all = ""; all += rs.getString("aId")+","; all += rs.getString("aName")+","; all += rs.getString("aHukou")+","; String fundc = rs.getString("aFundc"); String a = fundc.substring(0, fundc.length()-1); String b = a.split(",")[a.split(",").length-1]; all += b+","; String fundp = rs.getString("aFundp"); String c = fundc.substring(0, fundp.length()-1); String d = c.split(",")[c.split(",").length-1]; all += d+","; list.add(all); } rs.close();//关闭资源 } con.close();//关闭数据库 for(int i=0;i