简体   繁体   中英

invalid sql statement in servlet

In login page i make validation that user is allowed to enter system , i make methode which validate user:

 boolean isValidUser(Connection con,String userName,String pass ){}

it works correctly in desktop Application, but when i tried it in servlet it makes exception that table or view doesn't exist ??? but the table is aleady exist in my db ?? Can somebody tell me where is the problem?

this is the method

public boolean isValidUser(Connection con,String userName,String pass )throws SQLException
{
    String selSQL="SELECT USER_NAME, USER_PASS FROM OSQS_USERS where USER_NAME =? and USER_PASS =?";
    ResultSet rs =null;
    boolean exist =false;
    PreparedStatement pstmt = null;
    try {

        pstmt = con.prepareStatement(selSQL);
        pstmt.setString(1,userName);
        pstmt.setString(2, pass);

        rs=pstmt.executeQuery();
        if(rs.next())
            exist= true;

    }
//close statment and result sest 
return exist;
}

Given that the same code executes correctly in the context of a desktop application, you might want to check the JDBC connectivity details that are being utilized to retrieve the connection in the servlet.

This is important in the case of databases like Oracle, since multiple database user accounts can exist in a single database installation. It is quite possible that a separate Oracle user account was utilized in the context of the database application and another in the context of the servlet. In Oracle, database objects are owned by a particular user, and if another account wishes to access the same, then privileges must be granted to the second account.

If you cannot change the credentials used to access the database from the servlet, consider granting the necessary privileges (SELECT in this case) to the second user, although I must admit that it would not solve your problem completely. The second database user account, would require rights on more or less all the objects owned by the first, for it is unlikely that your application was designed to use multiple database accounts.

If Oracle is telling you that a table or view "does not exist", then it is telling you that it cannot find them ... even if you think that it should find them.

I would hazard a guess that you are connecting to a different Oracle database when running in your desktop application and in a servlet. This may be by design or by accident.

Take a look at your respective JDBC configurations; specifically the connection URLs.

(It is also possible that this is a permissions problem. But I'd have thought that Oracle would tell you that you don't have permission to use the table or view ... rather than telling you that it doesn't exist.)

EDIT

I suspect that the root problem is that the 'localhost' in the JDBC URL is sending you to different hosts (and hence Oracle database servers) in the desktop and servlet cases. Try using the actual DNS name of the server that contains the database you are trying to use.

if yes,where should i add data to orcle db to make testing for my application

You should be asking your local database administrator that question!

数据库用户可能是与表所有者不同的用户,因此,除非您授予对该表的选择权限(并为所有引用加上前缀:tablename-> owner.tablename),否则Oracle不会允许您访问该表。

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