Announcement Announcement Module
Collapse
No announcement yet.
Why the code can work in MySQL and can not work in Oracle Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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

      Comment

      Working...
      X