Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students explore these related Databases questions