import java.net.URL;
import java.sql.*;

class Repro1 {

    // Bug reported - For a numeric in a table defined by:
    //   CREATE TABLE SERG (F01NUM NUMERIC) ;
    // , the precision and scale reported by
    // ResultSetMetaData.getScale() and 
    // ResultSetMetaData.getPrecision() are value -1 

    // To run repro, you must first create the table "SERG" in a postgreSQL
    // database
    // and then modify the url, userid and password in this program
    // to appropriate values. Notice that output from program shows
    // precision = -1, scale = -1


    public static void main (String args[]) {

        String url = "jdbc:postgresql://edared30:5432/qaeda";
        Connection con = null;
        PreparedStatement stmt = null;
        ResultSetMetaData rsmd = null;
        String sel = "SELECT F01NUM FROM SERG";

        try {

            // Load the postgreSQL jdbc driver

            Class.forName ("org.postgresql.Driver");

            con = DriverManager.getConnection (
                url, "userid", "pwd");

            stmt = con.prepareStatement(sel);
    
            rsmd = stmt.getMetaData();

            int prec = rsmd.getPrecision(1);
            int scale = rsmd.getScale(1);

            System.out.println("\nColumn 1 precision is "+prec);
            System.out.println("\nColumn 1 scale is "+scale);

            stmt.close();
            con.close();
        }

        catch (SQLException ex) {

            // A SQLException was generated.  Catch it and
            // display the error information.  Note that there
            // could be multiple error objects chained
            // together

            System.out.println ("\n*** SQLException caught ***\n");

            while (ex != null) {
                System.out.println ("SQLState: " +
                        ex.getSQLState ());
                System.out.println ("Message:  " + ex.getMessage ());
                System.out.println ("Vendor:   " +
                        ex.getErrorCode ());
                ex = ex.getNextException ();
                System.out.println ("");
            }
            return;
        }
        catch (java.lang.Exception ex) {

            // Got some other type of exception.  Dump it.

            ex.printStackTrace ();
        }
    }
}
