• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

prepareCall error

 
Manu Quartier
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a problem with a prepareCall. When I get the value returned by the stored procedure ("statement.getString(2)"), I recieve a "null" value. Can somebody help me ?
Java code :
public static void main(String[] args) {
try {

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
Connection c;
CallableStatement statement;
ResultSet results;
c = DriverManager.getConnection("jdbcdbc:EquadisTestAvi", "sa", "");

statement = c.prepareCall("{call gfi_compt(?,?)}");

statement.setString(1, "eq_contact_id");
statement.registerOutParameter(2, java.sql.Types.INTEGER);

statement.execute();
System.out.println("cptr: " + statement.getString(2));

} catch (SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
Stored procedure :
CREATE PROCEDURE GFI_COMPT
@COMPTEUR VARCHAR(20),
@VALEUR INT OUTPUT
AS
SELECT @VALEUR = (SELECT MAX(VALEUR)+1 FROM GFI_COMPTEUR WHERE COMPTEUR_ID = @COMPTEUR)
IF @VALEUR IS NULL
BEGIN
SET @VALEUR = 1
INSERT INTO GFI_COMPTEUR (COMPTEUR_ID,VALEUR) VALUES (@COMPTEUR,@VALEUR)
END
ELSE
UPDATE GFI_COMPTEUR SET VALEUR = @VALEUR WHERE COMPTEUR_ID = @COMPTEUR
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic