package javatemplate1; import java.sql.*; import java.sql.ResultSet; // for result set import java.sql.Statement; import java.util.logging.Level; import java.util.logging.Logger; import static jdk.internal.org.objectweb.asm.util.Printer.TYPES; public class JavaTemplate1 { // example of public static void main(String[] args) { // TODO code application logic here System.out.println("main block executing "); Connection c = null; //manage copnnection Statement st = null;// query statement support ResultSet rs = null;// active connection database result // String dbURL = "jdbc:postgresql://localhost:5432/pgsdemo1"; //String user = "postgres"; String pwd = "postgre_manas9"; String dbURL = "jdbc:mysql://localhost/test?"; String user = "Manas9"; String pwd = "Manas9237"; // String sql1 = "select round (cfcal65.25), 2); " ; String sql1 = "{?=call ctof(36.25)}" ; double d1 = 29.25; // connecting to db try { // Connection>>statement >> Resultset >> c = DriverManager.getConnection(dbURL,user,pwd); CallableStatement stmt = c.prepareCall(sql1); stmt.registerOutParameter(1,Types.DOUBLE); rs = stmt.executeQuery(); //st = c.createStatement(); //rs = st.executeQuery(sql1); Process.loaddata(rs , 1); } catch (SQLException ex) { ex.getErrorCode(); String message = ex.getMessage(); System.out.println(message); } finally { System.out.println("going through final block"); try { if (st== null || st.isClosed()) { } else { st.close(); } if (c != null && !c.isClosed()) { c.close(); } } catch (SQLException ex) { ex.getErrorCode(); ex.getMessage(); } } System.out.println("dis-Connected to database successfully"); } } class Process { // public static void loaddata(ResultSet x1 , int n2) throws SQLException { int size = 0; while ( x1.next() ) { size++; for ( int i = 1; i <= n2; i++ ) try { System.out.printf( "Centigrade 43.25 = " + x1.getObject( i ) + " Fahrenheit"); } catch (SQLException ex) { Logger.getLogger(Process.class.getName()). log(Level.SEVERE, null, ex); } System.out.println(); } //displayMap(list1); System.out.println("processed rows :: "+ size); } }