简体   繁体   中英

Error in compilation of java code

shilps.java:198: cannot find symbol
symbol  : method setDate(int,java.lang.String)
location: interface java.sql.PreparedStatement
                        ps.setDate(2, "2010-05-31");
                          ^
shilps.java:231: cannot find symbol
symbol  : method setDate(int,java.lang.String)
location: interface java.sql.PreparedStatement
            ps.setDate(1, "2010-05-31");
              ^
shilps.java:232: setInt(int,int) in java.sql.PreparedStatement cannot be applied to
 (int,java.lang.String)
                        ps.setInt(2, "88349");
                          ^
shilps.java:293: e is already defined in main(java.lang.String[])
           }catch(Exception e){
                            ^
6 errors

Why the error is occurring? I have included:

 import java.util.*;
    import java.io.*;
    import java.sql.*;
  1. the 2 param method in PreparedStatement for setDate takes a Calendar, not a String
  2. the 2 param method in PreparedStatement for setDate takes a Calendar, not a String,
  3. the 2 param method for setInt takes two int s, not and int and a String.
  4. you already have another field in your main method called e .

The compiler tells you everything you needd to know:

setInt(int,int) in java.sql.PreparedStatement cannot be applied to (int,java.lang.String)

This means, you are passing a Value of Type String to a methods witch needs a int . The API-Doc of PreparedStatement will show you, that there is a Method setString(int,String) which will take a String as second Parameter.

http://download.oracle.com/javase/1.4.2/docs/api/java/sql/PreparedStatement.html

Maybe you wanted to call ps.setInt(2, 88349);

There ist a valiable called e already defined in that scope.

try{
    // some Code
    try{
        // some more coe
    } catch (Exception e){}
                      ^^^
              Compiling Error
} catch (Exception e){}

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