一个简单的问题 你在catch里面也应该写一个返回,或者在最后面写也可以 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 补充一下:你在成功的时候返回了conn对象,但是不成功哪?在发现异常,或者没有成功返回的情况下,你的返回代码没有写,编译器认为你的方法出口不完备。比如你写一个public boolean method(){ if(XXX){ return true; } else{ }}也会出同样的错误。 因为你的这个方法是有返回值的,而你在捕获异常时,只是把错误信息打出来,并没有返回任何东西。解决办法: 在异常处理中,最后都加个返回语句:return null; public Connection getConnection() throws SQLException,ClassNotFoundException{ Connection conn = null;try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:orac", "System", "manager"); }catch(ClassNotFoundException e1){ System.out.println("驱动程序装载错误"); e1.printStackTrace(); }catch(SQLException es){ System.out.println("sql语句执行错误"); es.printStackTrace(); } return conn; } public Connection getConnection() throws SQLException,ClassNotFoundException { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); return DriverManager.getConnection ("jdbc:odbc:orac", "System", "manager"); //return con; } catch(ClassNotFoundException e1) { System.out.println("驱动程序装载错误"); e1.printStackTrace(); } catch(SQLException es) { System.out.println("sql语句执行错误"); es.printStackTrace(); } return null; } 或者这样: Connection con = null; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:orac", "System", "manager"); } catch(ClassNotFoundException e1){ System.out.println("驱动程序装载错误"); e1.printStackTrace(); } catch(SQLException es){ System.out.println("sql语句执行错误"); es.printStackTrace(); } return con; accp(accp) ::你这就不能得到ResultSet了阿 :) java程序调用bat,总是报错,找不到main函数 checkstyle报protected错误 hibernate的 修改方法 关于从txt文档读取多组数据并赋值给不同变量的问题 struts问题,大家帮忙 大家新年快乐 对于数据量比较大,且访问量比较大的网站,谁有处理经验的,给题个建议阿 请推荐一本学j2ee的好书 请问:如何用会话外观转发实体的finder方法返回的Collection??? java 使用 itextpdf 生成PDf 多行文本 首行汉字显示不全 如何解决? 我疯掉了,大吓帮帮忙!!! jboss3在windows在怎样配置啊?
你在成功的时候返回了conn对象,
但是不成功哪?在发现异常,或者没有成功返回的情况下,你的返回代码没有写,编译器认为你的方法出口不完备。
比如你写一个
public boolean method(){
if(XXX){
return true;
}
else{
}
}
也会出同样的错误。
解决办法:
在异常处理中,最后都加个返回语句:return null;
Connection conn = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:orac", "System", "manager");
}catch(ClassNotFoundException e1){
System.out.println("驱动程序装载错误");
e1.printStackTrace();
}catch(SQLException es){
System.out.println("sql语句执行错误");
es.printStackTrace();
}
return conn;
}
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
return DriverManager.getConnection ("jdbc:odbc:orac", "System", "manager");
//return con;
}
catch(ClassNotFoundException e1)
{
System.out.println("驱动程序装载错误");
e1.printStackTrace();
}
catch(SQLException es)
{
System.out.println("sql语句执行错误");
es.printStackTrace();
}
return null;
}
Connection con = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:orac", "System", "manager");
} catch(ClassNotFoundException e1){
System.out.println("驱动程序装载错误");
e1.printStackTrace();
} catch(SQLException es){
System.out.println("sql语句执行错误");
es.printStackTrace();
}
return con;