Results 1 to 3 of 3

Thread: Why the code can work in MySQL and can not work in Oracle

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Posts
    18

    Default Why the code can work in MySQL and can not work in Oracle

    The code is following:

    public static final String DEF_USERS_BY_USERNAME_QUERY =
    "SELECT LOGINNAME,PASSWORD,ENABLED FROM APP_USER WHERE LOGINNAME = ? ";

    List users = usersByUsernameMapping.execute(username);

    protected class UsersByUsernameMapping extends MappingSqlQuery {
    protected UsersByUsernameMapping(DataSource ds) {
    super(ds, usersByUsernameQuery);
    declareParameter(new SqlParameter(Types.VARCHAR));
    compile();
    }

    protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
    String username = rs.getString(1);
    String password = rs.getString(2);
    boolean enabled = rs.getBoolean(3);
    UserDetails user =
    new User(
    username,
    password,
    enabled,
    new GrantedAuthority[] {
    new GrantedAuthorityImpl("HOLDER")});

    return user;
    }
    }

    The code can retrieve record from database in MySQL, but in Oracle it doesn't return any record. why??

  2. #2
    Join Date
    Sep 2004
    Posts
    18

    Default

    And then I test the hibernate code,I found that it do well with mysql, and didn't return any record in oracle .
    I don't know where the error.

  3. #3
    Join Date
    Aug 2004
    Posts
    26

    Default

    I'm guessing that LOGINNAME is a CHAR - you will need to either
    1: pad the bind value to the correct length
    2: use
    Code:
    oracle.jdbc.OraclePreparedStatement.setFixedCHAR()
    instead of
    Code:
    java.sql.PreparedStatement.setString()
    3: change it to a VARCHAR2

    Regards,
    Gordon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •