Hi, all. Wonderful forum you all got here. Seems like a good group
So here's an off-the-wall thread for you guys. I'm not wondering how to fix a problem. I'm wondering why something isn't breaking, or more aptly, isn't still broken. Here's the run-down:
I'm learning JSP and Servlets on my own. I thought what better way than to create a simple login page. I ran into the "No suitable driver found" error message and after much Googling did not find a solution that worked for me. I had the JDBC driver for Postgres in my build path and darnit I thought that's all I should have to do. Well, then I found a suggestion that I thought got me a step further and that was using Class.forName("org.postgresql.Driver"). Well, then that resulted in a Class Not Found exception. Fooey, I thought. Back to the Google.
So buried in the search results was a simple suggestion: add the JAR file to Tomcat's /lib folder. I removed the forName() line and JAR from the class path (per the suggestion the latter was useless). Ran the JSP and woila, everything worked. You'd think I'd be happy but now I'm burdened by something else: why is this working without forName()? There are dozens of search results that indicate this is required. I shut down and re-opened Eclipse, tried putting forName() back in the Servlet and it still throws an exception. Below are screen shots of my project:
Any ideas? Thanks in advance.
Edit: the pictures in the post don't show much so here's the direct links:
Loading the driver manually isn't required if you're using a JDBC 4.0 compatible driver, because the service provider mechanism is used. Have a look at the DriverManager API documentation for more details, but it basically boils down to the JDBC driver's JAR needing a file called java.sql.Driver in META-INF/services that contains the fully-qualified name of the driver class.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop