先说结论:
1.我们对结果集的next()方法需要用while进行包裹,如果是if就只能执行一次 (第36行)
2.我们返回的是多个和数据库表中对应的Java对象,需要用集合进行收集 (第1行)
代码展示:
//针对customer表的查数据的操作 多个占位符
public static ArrayList<Customers> select_many(String sql, Object ...args){ //...代表可以有多个数据
ArrayList<Customers> list = new ArrayList<>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
//1.连接数据库 (1.通过反射获取配置文件的信息 2.加载驱动 3.进行连接)
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("jdbc.properties");
Properties pros = new Properties();
pros.load(is);//将数据字节流数据读取到pros集合中
String user = pros.getProperty("user");
String password = pros.getProperty("password");
String url = pros.get