新手求救,谢谢
能否帮忙看下下面两个问题:
一:为什么init()方法必须被private?请举例说明。
class Test
{
public Test()
{
init();
}
private void init()
{
…
}
}
二:请找出下面程序的错误
class Test
{
public static void executeQuery( String connectionName, String statementText) throws SQLException
{
Connection connection = null;
try
{
//Get a connection from connection pool
connection = manager.getConnection(connectionName);
Statement statement = connection.createStatement();
ResultSet resultSet =
statement.executeQuery(statementText);
for (int i = 0; resultSet.next(); i++)
{
...
}
resultSet.close();
statement.close();
return ; }
catch (SQLException e)
{
throw(new SQLException(statementText));
}
}
}
能否帮忙看下下面两个问题:
一:为什么init()方法必须被private?请举例说明。
class Test
{
public Test()
{
init();
}
private void init()
{
…
}
}
二:请找出下面程序的错误
class Test
{
public static void executeQuery( String connectionName, String statementText) throws SQLException
{
Connection connection = null;
try
{
//Get a connection from connection pool
connection = manager.getConnection(connectionName);
Statement statement = connection.createStatement();
ResultSet resultSet =
statement.executeQuery(statementText);
for (int i = 0; resultSet.next(); i++)
{
...
}
resultSet.close();
statement.close();
return ; }
catch (SQLException e)
{
throw(new SQLException(statementText));
}
}
}
{
...
}
while(rs.next)
{
...
}
二、 for (int i = 0; resultSet.next(); i++)
{
...
}
该语句会因为游标越界而报错,没有退出循环的条件,resultSet.next()为布尔型变量,而for语句中必须为三个表达式。传统标准写法:
whlie(resultSet.next()){
}