pgsql_StoredFunc_java1.htm
 
Screen Shots:


Runtime display

Script:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapp1;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Manas
*/
public class JavaApp1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("main block executing ");
Connection con = null;
Statement st = null;
ResultSet rs = null;
PreparedStatement pst = null;
//
String url = "jdbc:postgresql://localhost/pgsdemo1";
// String user = "manas237";
// String password = "pwmanas237";
String user = "postgres";
String password = "postgre_manas9";
System.out.println("host user and password ---passd through ");
try {
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
// rs = st.executeQuery("SELECT VERSION()");
rs= st.executeQuery("select round(cfcal(29.25),2)");
//
if (rs.next()) {
System.out.println(rs.getString(1));
}

System.out.println("Data Base connected ");

} catch (SQLException ex) {
Logger lgr = Logger.getLogger(JavaApp1.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);

} finally {
try {
if (rs != null) {
rs.close();
System.out.println("Resultset from executeQuery... closed");
}
if (st != null) {
st.close();
System.out.println("Statement createStament... closed");
}
if (con != null) {
con.close();
System.out.println("DB connection... cloased");
}
System.out.println("finally block executing ");
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(JavaApp1.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
// main block ends here
}
}