• Post Reply Bookmark Topic Watch Topic
  • New Topic

Coding help required  RSS feed

 
Kerin Kapoor
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Below is what I want to achieve but I'm having trouble extracting records from Oracle...

1. Extract guid from a table in Oracle
2. Connect to ldap and pass the guid to retrieve some information out of LDAP - complete
3. insert the extracted records into a table in Oralce.

The 2 errors I'm getting are as follows -

1. non-static variable this cannot be referenced from a static context
this.oguid = rs.getString(1);

2. cannot find symbol
symbol : varibale oguid
location: class Gname
this.oguid = rs.getString(1);

I'm new to java so any help would be appreciated!! Thanks in Advance!!!



 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. non-static variable this cannot be referenced from a static context

The error message itself is self explanatory. this is a non-static variable, main is a static method. I hope you can now guess where the problem is.
 
Kerin Kapoor
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply...I understand what youmean - that I cannot use this inside main.

But how to I fix this and then compile it??.. I'm New to java so any pointers will be appreciated...
Thank you..
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have declared the variable in main method itself, i.e. it's a method local variable. So remove this. , you don't need object.variable name to refer to method local variables.
 
Campbell Ritchie
Marshal
Posts: 56521
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you got such a long main method?
 
Kerin Kapoor
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for pointing my silly mistake.

Though I was able to resolve the previous error. I'm getting a new error on the statements where I'm trying to connect to Oracle and execute queries..

The error is given below -

unreported exception java.sql.SQLException; must be caught or declared to be thrown..

I've tried connecting to Oracle using below mentioned methods -

Connection con = DriverManager.getConnection("jdbc:‍oracle:thin:@hostname:portnumber:testdb","username","password");
Connection con = DriverManager.getConnection("jdbc:derby://hostname:portnumber/testDB","username","password");

Any pointers will be appreciated.

Thank you..

 
Campbell Ritchie
Marshal
Posts: 56521
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got rid of the inappropriate in your post; if that happens again try putting ‍ between : and o or clicking the “disable smilies…” box below.

You can find out all about Exceptions in the Java Tutorials.
 
Kerin Kapoor
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply..

I kind-off figured it out how to use exception handling in java by using your link...

and found out that my program is unable to find the driver for connecting to oracle data base..

Please refer to my post here - http://www.coderanch.com/t/627823/JDBC/databases/Java-program-Connect-database

The error is given below -
The program gets compiled but I get the below error while running the program -

java.lang.classNotFoundException: 3Doracle.jdbc.driver.OracleDriver
JDBC Class found
SQL exception occured java.sql.SQLException: No suitable driver found for jdbc: oracle thin:@hostname:port:dbname


How do I make my java program look for the driver present under wlserver_10.3/server/lib/ojdbc6_g.jar

Thanks, Gaurav
 
Campbell Ritchie
Marshal
Posts: 56521
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you put the files with the driver in? How are you adding that to your classpath?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!