简体   繁体   中英

No suitable method found for setString

I'm writing a method that calls a stored procedure in a MSSQL database. The stored procedure has 4 inputs, all numbers. I'm using setString() to enter the paramaters for the stored procedure.

I'm getting the following compile error

no suitable method found for setString(int, int)

It seems to want setString(int, string) but the parameters i need to pass are ints,not strings.

Is there a way to pass ints or do I have to convert the int s to string ?

public void genRoadMap(int id, int semester, int debug, int units)
{
   CallableStatement c = null;
   try
   {
        c = connection.prepareCall("{call dbo.GenerateRoadMap(?, ?, ?, ?)}");
        c.setString(1, id);           
        c.setString(2,semester);
        c.setString(3,debug);
        c.setString(4,units);
        c.execute();
   }
   catch (Exception ex)
   {
       ex.printStackTrace();
   }
}

You have to convert the int s to a String if that's what the method signature expects. You can use the String.valueOf() method to accomplish this.

To address what you said in the comment: if you are attempting to have the procedure process the data as an int , you need to pass the data in as such using the appropriate method in CallableStatement (in this example, setInt() ).

c.setInt(1, 100); // For integers
c.setString(2, "string"); // For strings
c.setDate(3, new Date()); // For dates

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM