QueryRunner
来源:9-2 项目作业
scandinavian
2020-07-28 16:02:00
private static QueryRunner getQueryRunner() throws Exception{
Properties properties = new Properties();
String propertyFile = NewsApp.class.getResource("/druid-config.properties").getPath();
QueryRunner qr = null ;
try {
propertyFile = new URLDecoder().decode(propertyFile, "UTF-8");
properties.load(new FileInputStream(propertyFile));
DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
qr = new QueryRunner(dataSource);
} catch (Exception e) {
e.printStackTrace();
}
return qr; // 请问老师 return QueryRunner instance 是应该写在这里还是写在 try 里 ??? thx
}2回答
同学你好,写在这里即可。

如果书写在try中,方法会提示没有返回值。且出现异常时,catch并不会起到任何作用,因为在try中已经return了

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
好帮手慕小脸
2020-07-28
同学你好,这里QueryRunner instance是指什么呢?在上述代码并没有体现出来。建议同学重新描述。
注:这里返回qr就已经可以了
祝学习愉快~