从sql获取数据-在intellij中生成代码

qvsjd97n  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(160)

在从sql查询中获取数据时,是否有一种自动生成代码的方法?
示例(请注意这两条注解)

public static List<VehicleFinding> getVehicleFindings(Connection connection, String vehicleId) {
    List<VehicleFinding> vehicleFindings = new ArrayList<>();

    try (Statement statement = connection.createStatement();
         ResultSet rs = statement.executeQuery("select * " +
                 "from kjlv.vehicle_findings " +
                 "where vehicle_id = " + vehicleId + ";")) {
        rs.last();
        int rowCount = rs.getRow();
        Log.i(TAG, "getVehicleFindings " + rowCount + " rows(s).");
        rs.first();
        if (rs.first()) {
            do {
                // ---START--- GENERATE THIS CODE AUTOMATICALLY
                int id = rs.getInt("id");
                vehicleFindings.add(new VehicleFinding());
                // ----END---- GENERATE THIS CODE AUTOMATICALLY
            } while (rs.next());
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return vehicleFindings;
}

我已经有了由pojo.groovy脚本创建的类。现在,我正在寻找一种解决方案,以便在加载带有特定数据的对象构造函数时创建语句。。
在其他项目中,我使用hibernate,但在我当前的项目中,我无法使用hibernate。
提前谢谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题