如下面:
private Connection getFrom(){
try {
try { } catch (Exception ex) {
ex.toString());
}
} catch (IOException er) {
er.printStackTrace();
}
return n;
}
private Connection getFrom(){
try {
try { } catch (Exception ex) {
ex.toString());
}
} catch (IOException er) {
er.printStackTrace();
}
return n;
}
解决方案 »
- 一个JTable 放在JScrollPane中,如果这个JTable有50行,而JScrollPane中一页只能显示20行,我想让JTable 从第25行开始显示,怎么做?
- 求编写程序切两个数的最大公约数和最小公倍数
- 帮助改一下程序吧。
- %B6%A5%D2%BB%CF%C2%0D%0A%26看起来是什么编码?
- 急啊,Tree的问题,谁能给我点思路
- E J B 2.0 中关于CMP 两个Bean 之间关系很困惑的问题?
- 热点!!!
- 能不能使数组内的元素也是由数组组成的?
- 关于JBuilder5安装的问题,请救命!
- while(true)对有返回值得java方法调用的影响
- DatagramPacket构造方法中的ip写法
- InputStream 和 InputStreamReader 的区别??
不过貌似实际意义不大,也没见有人这么用.
Connection trueConn = null;
FileProperty sqlProperty = null;
try {
sqlProperty = new FileProperty("SQLconnection.properties");
try {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName( sqlProperty.getProperty("db.driverName"));
ds.setUsername(sqlProperty.getProperty("db.username"));
ds.setPassword(sqlProperty.getProperty("db.password"));
ds.setUrl(sqlProperty.getProperty("db.URL"));
trueConn = ds.getConnection();
} catch (Exception ex) {
System.out.println("数据连接出错了:" + ex.toString());
}
} catch (IOException er) {
er.printStackTrace();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
上面的try 是否正确?
sqlProperty.close();
return trueConn;
}
Connection trueConn = null;
FileProperty sqlProperty = null;
try {
sqlProperty = new FileProperty("SQLconnection.properties");
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(sqlProperty.getProperty("db.driverName"));
ds.setUsername(sqlProperty.getProperty("db.username"));
ds.setPassword(sqlProperty.getProperty("db.password"));
ds.setUrl(sqlProperty.getProperty("db.URL"));
trueConn = ds.getConnection();
} catch (SQLException ex) {
System.out.println("数据异常");
} catch (IOException er) {
er.printStackTrace();
} catch (Exception er) {
er.printStackTrace();
}
Connection trueConn = null;
FileProperty sqlProperty = null;
try {
sqlProperty = new FileProperty("SQLconnection.properties");
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(sqlProperty.getProperty("db.driverName"));
ds.setUsername(sqlProperty.getProperty("db.username"));
ds.setPassword(sqlProperty.getProperty("db.password"));
ds.setUrl(sqlProperty.getProperty("db.URL"));
trueConn = ds.getConnection();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
System.out.println("数据连接出错了:" + e.toString());
} finally {
if (sqlProperty != null) {
sqlProperty.close();
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
//上面的try 是否正确?
//try 块语法上完全可以嵌套,有问题的地方在 sqlProperty.close();
//可以把多个嵌套的 try 合并以简化程序逻辑
//另外捕获到异常最好包装成你自己的异常或者直接把异常抛出去让调用者决定如何处理
return trueConn;
}