Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why am I getting this error?

 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Annette,
you need to catch a SQLException i would imagine, i.e. add another catch block

------------------
martin samm
m_sam@rroom.net
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you put a closing slash in the pathname?
pathName = "c:\\mydir\\mysubdir\\";
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic