Reputation: 3538
I have an app that is meant to write to a DB. I'm working with hsqldb for development.
I have a unit test that can write to a DB with the insertToDB()
method:
@Test
public void writeTest() throws SQLException {
LocationImpl li = new LocationImpl();
li.setName("TestName");
li.setState("PA");
li.setLattitude(100);
li.setLongitude(200);
LocationDAOImpl.insertIntoDB(li);
ResultSet rs = LocationDAOImpl.getAllLocations();
int i = 0;
while (rs.next()){
i++;
if (i==591) { assertEquals("TestName", rs.getString(7)); }
}
}
When I call it here, I get the following error.
java.sql.SQLException: No suitable driver found for jdbc:hsqldb:file:C:/Users/my/hsqldb/dir
:
Controller code:
@RequestMapping(value = "/addLocation", method = RequestMethod.POST)
public ModelAndView addLocation(@ModelAttribute("LocationImpl")LocationImpl locationImpl,
ModelMap model) throws SQLException {
logger.info("Form submission method called");
model.addAttribute("name", locationImpl.getName());
LocationDAOImpl.insertIntoDB(locationImpl);
return new ModelAndView("result", "command", locationImpl);
}
Any thoughts on why the connection works from jUnit, but not from the webapp? Thanks
Upvotes: 0
Views: 79
Reputation: 5282
Because the HSQLDB JDBC driver is on the test classpath, but not on the runtime classpath.
Upvotes: 1