File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes why am I getting this error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "why am I getting this error?" Watch "why am I getting this error?" New topic
Author

why am I getting this error?

Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Error = "Must be caught or declared to be thrown"
I'm getting this error at the following line:
con = DriverManager.getConnection(dbProps.getProperty("db.driver"), dbProps.getProperty("db.user"), dbProps.getProperty("db.password"));
Any idea why I would be getting this error?
Annette
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
There are methods that might generate exceptions when they are used. In your case you just have to put your statements in try-catch block and throw an exeptions. Check which exception these methods generate and throw them or I think you can just through generic exception:
try{
// your db stuff
}
catch(Exeption exp){}
or if you have your db stuff in a separate functon:
someFunction()throw Exception_for_this_calls{
}
hope this helps,
Alex


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Well, my code is in try/catch blocks.
Here's the exact code:

The only other problem I've been getting, which I can get rid of by commenting out, is the "throw new ClassNotFoundException...".
Maybe I'm just not seeing something right. Is there a bracket missing or something?
martin samm
Ranch Hand

Joined: Nov 09, 2000
Posts: 31
Annette,
you need to catch a SQLException i would imagine, i.e. add another catch block

------------------
martin samm
m_sam@rroom.net


martin samm<BR>m_sam@rroom.net
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
That seemed to fix that error! thanks!
Does anybody know what a property file is supposed to look like?
I just went into notepad and wrote this:
db.driver=oracle.jdbc.driver.OracleDriver
db.user=inv_read
db.password=annette1
db.url=jdbc racle:thin:@ott46:1521:d10h
then I saved the file as a .properties file. Are you supposed to put anything special in them?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Since it appears that you are using the properties file from the code sample I sent you...
There is no standard! That format was made up by my development team. The code sample is looking for a file called db.properties in any directory you want but you must specify that directory when you call the connectToDatabase() method.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Thanks Thomas!
I don't know what the problem is then. I've even tried just reading the file with the dbProps.getProperty() and outputting whatever it says, and I get nothing. I'm trying to find some more documentation on this stuff so that I can better understand it. It doesn't seem like it should be too complicated, but hey.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Did you put a closing slash in the pathname?
pathName = "c:\\mydir\\mysubdir\\";
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Ok! Seems to work, or at least partially. I can now read from the file. I think I had the wrong path, or I had written it wrong. I also did not know about the double "\".
Thanks for now! (I'm sure there will be more questions later...)
Annette
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why am I getting this error?