I'm working on querying a local MySQL database using a Java Spring application with JDBC. My application configures a DataSource
object using the SimpleDriverDataSource()
constructor. Then it makes a JDBCTemplate
object from that DataSource
.
It's supposed to be running queries on the MySQL database through that template object, but the queries are failing for some unknown reason! I think it may have something to do with my DataSource
.
Here are the relevant bits of code. First, I configure a Data Source object like so:
public DataSource getDataSource() {
DataSource dbsrc = null;
try {
dbsrc = new SimpleDriverDataSource(new com.mysql.jdbc.Driver(), "jdbc:mysql://localhost/test?useSSL=false", "root", "");
} catch (SQLException e) {
e.printStackTrace();
}
return dbsrc;
}
In debugging, the dbsrc
appears to get defined. Whether or not it's correctly defined is another story. Here's a clip of what Eclipse says it is after it's definition:
dbsrc definition
I'm thinking something is not right about connectionProperties
being null
.
Here is an example of a query that is failing:
final List<String> methods = jdbcTemplate.query(methodsQuery, new RowMapper<String>() {
@Override
public String mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getString("PLANETDISCMETH");
}
});
When I step through that statement's execution, it enters the jdbcTemplate.query()
method and appears to throw an exception at some step that I cannot see (Eclipse tells me the source file cannot be found in the project).
Any help would be greatly appreciated and I'm happy to provide any other necessary information. Thank you!