2024.6.4

第六十三天

所花时间:2小时

代码量:200+

博客量:1

了解到的知识点:

政策查询2

dao层

package com.example.keji.dao;

import com.example.keji.entity.policy;
import com.example.keji.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class policydao {
    private static final String TAG = "mysql-tb_user-policyDao";
    public static List<String> search(String keyword) throws SQLException {
        List<String> zhengce = new ArrayList<>();
        Connection conn = JDBCUtils.getConn();
        String sql = "select from tb_user.policy where name like ?";
        if (conn != null) {
            PreparedStatement pstmt = conn.prepareStatement(sql);
            if (pstmt != null) {
                pstmt.setString(1,keyword);
                ResultSet rs = pstmt.executeQuery();
                while (rs.next()) {
                    String lu = rs.getString("name");
                    zhengce.add(lu);
                }
                rs.close();
                pstmt.close();
                conn.close();
            }
        }
        return zhengce;
    }

}

 

posted @ 2024-06-17 01:56  cvjj  阅读(4)  评论(0)    收藏  举报