Question: please rewrite the below code to print same output using recursive expressions import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import

please rewrite the below code to print same output using recursive expressions import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Objects; import java.util.Scanner; public class DfsSubParts { static final String url = "jdbc:postgresql://cisdb/snaredla"; static final String username = "snaredlaweb"; static final String PASS = "naredla15o2"; static PreparedStatement pstmt; public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the smaller part"); String part = sc.next(); if (part != null && part.length() != 0) { try { Connection conn = DriverManager.getConnection(url, username, PASS); Statement stmt = conn.createStatement(); recursionCall(part, stmt); } catch (SQLException e) { System.out.println(" exception while connecting to the datebase /processing the DFS"); } } else { System.out.println("please give us a part to do DFS"); } } public static void recursionCall(String part, Statement stmt) throws SQLException { System.out.print(part + " "); String part_1 = ""; String sql = "select MINOR_P from part_structure where MAJOR_P = ? and MINOR_P > ? order by MINOR_P"; try { pstmt = stmt.getConnection().prepareStatement(sql); pstmt.setString(1, part); pstmt.setString(2, part_1); ResultSet rs = pstmt.executeQuery(); if (Objects.nonNull(rs)) { while (rs.next()) { part_1 = rs.getString("MINOR_P"); // System.out.println("lower part " + lowerPart); System.out.println(" "); recursionCall(part_1, stmt); // recursively call the function with the lower part } } else { System.out.println("resultset for the part" + part + " is empty"); } } catch (Exception e) { System.out.println(" exception while processing the DFS"); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!