java - Connecting to Oracle with JDBC causes queries to return zero rows. -
so have been playing around querying databases using standard
statement s = connection.createstatement(); resultset rs = s.executquery(querystring); resultsetmetadata rsmd = rs.getmetadata(); while(rs.next)){ string code = ""; string value = ""; for(int = 1; <= rsmd.getcolumncount(); i++){ object obj = rs.getobject(i); if(i == 1){ code = obj.tostring(): } else{ label = obj.tostring(); } } //store code , labels in map } ...go on close statement , move on.
i trying select 2 columns table in each instance.
for part works well. when working mysql & microsoft sql databases result set full of data in table. when try oracle database empty result set.
i have tested query string in sql developer application , works fine, returns data. result set doesnt contain anything. resultset metadata says has 2 columns though. there need when interacting oracle database different other two? thanks.
if query works when run against oracle database, , know code works since you've run against mysql, other things try are:
1.) make sure jdbc connection url correct. sure connecting database intend to? (i.e. - 1 return rows expect?)
2.) take account credentials. make sure using same credentials through jdbc when connecting oracle directly.
3.) make sure both connections being made same machine , same environment. oracle drivers rely on environment variables find file (i believe called tnsnames.ora, or that) contains alias & connection info. getting different versions of file point different oracle instances.
4.) try manually specifying schema name in query. instead of select * my_table
use select * my_schema.my_table
. oracle clients configure sessions have default schemas set in preferences.
5.) if attempting select data you've inserted oracle client, make sure you've committed transaction in oracle client data visible other sessions.
one last debugging tool use try connecting via squirrel db client. squirrel 100% pure java sql client connects db using jdbc. test make sure jdbc driver, connection url, etc. valid.
Comments
Post a Comment