当前位置: 技术问答>java相关
请问这段代码为什么会出现return without value from....
来源: 互联网 发布时间:2015-07-14
本文导语: 函数: private String getrs1(String AUTITECOD) throws IOException, ServletException { try{String url="jdbc:oracle:oci8:xwrz/xwrz@oracle"; //加载驱动程序 Class.forName("oracle.jdbc.driver.OracleDriver")...
函数:
private String getrs1(String AUTITECOD)
throws IOException, ServletException {
try{String url="jdbc:oracle:oci8:xwrz/xwrz@oracle";
//加载驱动程序
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs;
//关联代码表
//String AUTITECOD="3";
rs=stmt.executeQuery("SELECT ID FROM AUTHITECOD WHERE AUTHITECOD.AUTHITE='"+AUTITE+"'");
rs.next();
AUTITECOD=rs.getString("ID");
rs.close();
return AUTITECOD;}
catch(Exception e){
System.out.println("SQLException:"+e.getMessage());
}
调用语句:public void saveToDB(){
try{
String url="jdbc:oracle:oci8:xwrz/xwrz@oracle";
//加载驱动程序
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs;
String AUTITECOD="";
AUTITECOD=getrs1(AUTITECOD);
.............
}
编译时无法通过,每次都提示return without value from private String getrs1
private String getrs1(String AUTITECOD)
throws IOException, ServletException {
try{String url="jdbc:oracle:oci8:xwrz/xwrz@oracle";
//加载驱动程序
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs;
//关联代码表
//String AUTITECOD="3";
rs=stmt.executeQuery("SELECT ID FROM AUTHITECOD WHERE AUTHITECOD.AUTHITE='"+AUTITE+"'");
rs.next();
AUTITECOD=rs.getString("ID");
rs.close();
return AUTITECOD;}
catch(Exception e){
System.out.println("SQLException:"+e.getMessage());
}
调用语句:public void saveToDB(){
try{
String url="jdbc:oracle:oci8:xwrz/xwrz@oracle";
//加载驱动程序
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs;
String AUTITECOD="";
AUTITECOD=getrs1(AUTITECOD);
.............
}
编译时无法通过,每次都提示return without value from private String getrs1
|
It is not guaranteed that the "return AUTITECOD" will be executed.For example:if exception occurs when execute the "lass.forName()".the "return AUTITECOD" will never be excuted.
So the compiler will complaint that return without string.
You can insert "return null" in the end of the function of getrs1.That will work.And best regard
So the compiler will complaint that return without string.
You can insert "return null" in the end of the function of getrs1.That will work.And best regard
|
javapro(microft_hating) 的话简单的说就是:
在 System.out.println("SQLException:"+e.getMessage());后面加上一个return null;。不过我建议是throw e;
在 System.out.println("SQLException:"+e.getMessage());后面加上一个return null;。不过我建议是throw e;