未报告的异常java.sql.SQLException; 必须被抓住或宣布被扔?

尝试编译以下代码时遇到此错误。我想知道我做错了什么。

未报告的异常java.sql.SQLException; 必须被抓住或宣布被抛出

Class.forName(myDriver);

^

private void setupInfo() {

Driver driver = new org.gjt.mm.mysql.Driver();

String url = "jdbc:mysql://localhost:3306/test";

String username = "root";

String password = "123456";

String problemFeatureSpecTableName = "ProblemFeatureSpec";

String solutionFeatureSpectTableName = "SolutionFeatureSpec";

String classTableName = "Class";

String extraDataTableName = "ExtraData";

String casebaseTablename = "CaseBase";

String problemTableName = "Problem";

String solutionTableName = "Solution";

String inactiveContextsTableName = "InactiveContext";

String constantsTableName = "Constants";

dbInfo = new DBInfo(new JDBCDriverInfo(driverName, url, username, password),constantsTableName);

problemSpecInfo = new FeatureSpecRDBInfo(problemFeatureSpecTableName, classTableName, extraDataTableName);

solutionSpecInfo = new FeatureSpecRDBInfo(solutionFeatureSpectTableName, classTableName, extraDataTableName);

rdbCasebaseInfo = new RDBCaseBaseInfo(casebaseTablename, solutionTableName, problemTableName, inactiveContextsTableName);

}

回答:

您要么需要在方法中 异常:

public void setupInfo()

{

try

{

// call methods that might throw SQLException

}

catch (SQLException e)

{

// do something appropriate with the exception, *at least*:

e.printStackTrace();

}

}

或 抛出方法SQLException

private void setupInfo() throws SQLException

{

// call methods that might throw SQLException

}

以上是 未报告的异常java.sql.SQLException; 必须被抓住或宣布被扔? 的全部内容, 来源链接: utcz.com/qa/423625.html

回到顶部