Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help me to compile this

 
usher beck
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please see a code below. I am not able to compile this.

Tell me what I am doing wrong.

Thanks in advance for your help.



$ javac b.java
----------
1. ERROR in b.java (at line 9)
Class.forName(driver);
^^^^^^^^^^^^^^^^^^^^^
Unhandled exception type ClassNotFoundException
----------
The method put(Object, Object) in the type Hashtable is not applicable for the arguments (String, int)
----------
1 problem (1 error)

echo $CLASSPATH
.:/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/lib:/home/oracle/j/ojdbc6.jar


 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This:

info.put ("ResultSetMetaDataOptions", 1);

should probably read:

info.put ("ResultSetMetaDataOptions", "1");
 
usher beck
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:This:

info.put ("ResultSetMetaDataOptions", 1);

should probably read:

info.put ("ResultSetMetaDataOptions", "1");


thanks, this fix is worked

Still i need to resolve
javac b.java
----------
1. ERROR in b.java (at line 9)
Class.forName(driver);
^^^^^^^^^^^^^^^^^^^^^
 
usher beck
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
usher beck wrote:
Ulf Dittmer wrote:This:

info.put ("ResultSetMetaDataOptions", 1);

should probably read:

info.put ("ResultSetMetaDataOptions", "1");


thanks, this fix is worked

Still i need to resolve
javac b.java
----------
1. ERROR in b.java (at line 9)
Class.forName(driver);
^^^^^^^^^^^^^^^^^^^^^


thanks,
It is compiled now

Class.forName(driver);

need to be replaced with

Class.forName(driver).newInstance();

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
usher beck wrote:
Class.forName(driver);

need to be replaced with

Class.forName(driver).newInstance();

No, you should not call newInstance(). The forName() call does everything that needs to be done; additionally calling newInstance() might do harm (although it's unlikely).

What you do need to do is to handle the exceptions that these methods can throw (that's what "Unhandled exception type ClassNotFoundException" is trying to tell you).

Lastly, if you do the forName() thing, then the next line (DriverManager.registerDriver(...)) should definitely be removed - it duplicates what the forName() call does.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic