import java.sql.*; import java.util.ArrayList; import java.util.List; public class BaseDao { private final String USERNAME="root"; private final String PASSWORD=""; private final String DRIVER="com.mysql.jdbc.Driver"; private final String URL="jdbc:mysql://localhost:3306/test_home?characterEncoding=utf-8"; protected Connection con; protected PreparedStatement ps; protected ResultSet rs; /** * 建立连接 * @return */ public Connection getCon(){ try { Class.forName(DRIVER);//反射机制,加载驱动 con = DriverManager.getConnection(URL, USERNAME, PASSWORD); } catch (Exception e) { e.printStackTrace(); } return con; } /** *关闭连接 */ public void close(){ try { if(rs!=null){ rs.close(); } if(ps!=null){ ps.close(); } if(con!=null){ con.close(); } } catch (Exception e) { e.printStackTrace(); } } public List<Search> querySearch(){ List<Search> datas=new ArrayList<Search>(); try { con=getCon(); String sql="select * from search"; ps=con.prepareStatement(sql); rs=ps.executeQuery(); while(rs.next()){ Search s=new Search(rs.getInt("id"), rs.getString("search")); datas.add(s); } } catch (Exception e) { e.printStackTrace(); } return datas; } }

Tg171017 LV12
2023年1月9日
jwfadacai LV8
2022年5月11日
1973356987 LV13
2021年6月17日
小白jmhuang LV12
2021年4月14日
lan12138 LV8
2021年3月24日
123hzh LV5
2020年11月19日
邈话12123 LV9
2020年10月29日
果园6666 LV5
2020年6月26日
小仙女本仙haha LV8
2020年6月13日
13940562934 LV22
2020年6月3日

a2796831202
2023年12月20日
暂无贡献等级
你爹正在加载中 LV4
2023年7月18日
ling7314 LV4
2023年7月6日
三十一 LV2
2023年6月28日
Sleachp LV8
2023年5月5日
chen_jw LV10
2023年2月19日
Tg171017 LV12
2022年12月25日
微信网友_6191697646571520 LV6
2022年11月24日
微信网友_6040315240812544 LV8
2022年10月11日
憨豆先生 LV2
2022年5月12日