Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes 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
Marshal
Posts: 35279
384
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.
 
    Bookmark Topic Watch Topic
  • New Topic