当前位置: 技术问答>java相关
JSP中的包代码问题!
来源: 互联网 发布时间:2017-04-23
本文导语: 有如下一行代码: Connection conn = DriverManager.getConnection(sConnStr,"123","123"); 编译时报错: unreported exception java.sql.SQLException; must be caught or declared to be thrown Connection conn = DriverManager.getConnection(sConnStr,"123","123");...
有如下一行代码:
Connection conn = DriverManager.getConnection(sConnStr,"123","123");
编译时报错:
unreported exception java.sql.SQLException; must be caught or declared to be thrown
Connection conn = DriverManager.getConnection(sConnStr,"123","123");
加上try以后的代码:
try
{
Connection conn = DriverManager.getConnection(sConnStr,"123","123");
}
catch(SQLException ex)
{
System.err.println("connection:" + ex.getMessage());
}
依然出错:
illegal start of type try
Connection conn = DriverManager.getConnection(sConnStr,"123","123");
编译时报错:
unreported exception java.sql.SQLException; must be caught or declared to be thrown
Connection conn = DriverManager.getConnection(sConnStr,"123","123");
加上try以后的代码:
try
{
Connection conn = DriverManager.getConnection(sConnStr,"123","123");
}
catch(SQLException ex)
{
System.err.println("connection:" + ex.getMessage());
}
依然出错:
illegal start of type try
|
sorry
Connection conn=null;
try
{
conn = DriverManager.getConnection(sConnStr,"123","123");
}
catch(Exception ex)//这里抛出的异常不是SQLException
{
System.err.println("connection:" + ex.getMessage());
}
Connection conn=null;
try
{
conn = DriverManager.getConnection(sConnStr,"123","123");
}
catch(Exception ex)//这里抛出的异常不是SQLException
{
System.err.println("connection:" + ex.getMessage());
}
|
还需要catch(java.lang.ClassNotFoundException e)才可以