views:

63

answers:

3

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;
}
+2  A: 

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!

Stephen C
my database name is orcl and that is the db location "jdbc:oracle:thin://@localhost:1521/orcl but i make new user test which i add users to , becouse i don't want to use system user with full privileges , when i make connection to db i make con to orcl db , do u think here is the problem ? if yes,where should i add data to orcle db to make testing for my application
Alaa
+4  A: 

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.

Vineet Reynolds
+1  A: 

Your database user is probably a different user from the table's owner, so unless you grant select permissions to that table (and prefix all references: tablename -> owner.tablename) Oracle is not going to let you access that table.

gpeche