Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
    Bookmark Topic Watch Topic
  • New Topic

looking for help with datatype match

 
Charlie Petrie
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
I obviously have a datatype mismatch between my java code and the sp. the return value for the parameters used should be 2.974548 but 2.0 is returned instead.

here's the SQLServer stored procedure (the procedure works fine):

CREATE PROCEDURE PS_PRESENT_WORTH
@discount_interest_rate DECIMAL(8,4),
@sell_out_period DECIMAL(8,4)
AS
DECLARE @present_worth_of_1_per_period DECIMAL(8,6)

SELECT @present_worth_of_1_per_period = (1 - (1/POWER((1 + @discount_interest_rate), @sell_out_period)))/@discount_interest_rate

Return @present_worth_of_1_per_period
GO


here's my calling code:

import java.sql.*;

public class StoredProcCall2{
public static void main(String [] args){
StoredProcCall2 spc2 = new StoredProcCall2();
spc2.aMethod();
}
public void aMethod(){
String url;
String driver;
double a;
try{
url = "jdbc dbc:Videos";
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
Connection connection = DriverManager.getConnection(url);
CallableStatement cstmt = connection.prepareCall("{? = call PS_PRESENT_WORTH(?, ?)}");
cstmt.registerOutParameter(1, java.sql.Types.DOUBLE);
cstmt.setDouble(2, 0.13);
cstmt.setDouble(3, 4.0);
cstmt.execute();
System.out.println(a = cstmt.getDouble(1));
}catch(ClassNotFoundException cnfe){
System.err.println(cnfe);
}catch(SQLException sqle){
String sqlMessage = sqle.getMessage();
String sqlState = sqle.getSQLState();
int vendorCode = sqle.getErrorCode();
System.err.println("Message: " + sqlMessage);
System.err.println("SQL state: " + sqlState);
System.err.println("Vendor Code: " + vendorCode);
}
}
}

Thanks
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 35969
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Charlie,
Please don't post the same question multiple times.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!