在线等待,关于JSP函数中的数据集 (91分)

  • 主题发起人 主题发起人 BlueWin
  • 开始时间 开始时间
B

BlueWin

Unregistered / Unconfirmed
GUEST, unregistred user!
//我在Jsp中定义一个函数,部份代码如下
<%!
public String GetDiv(String DID,int Level,int MaxLevel)
{
com.impartsoft.sql.ChangeUnicode changebean = new com.impartsoft.sql.ChangeUnicode();
com.impartsoft.sql.ConnectionPool sqlbean = new com.impartsoft.sql.ConnectionPool();
String RetChar="",Sps="",D_ID="",D_Name="";
ResultSet rsDN = null;
int HaveChild=0;
for (int i=0;i<Level;i++)
{
Sps = Sps + "&amp;nbsp;&amp;nbsp;&amp;nbsp;";
}
rsDN = sqlbean.executeQuery("select top 1 DeptName from Department where DeptID='"+DID+"'");//这行有问题????

if (rsDN.next())
{
D_Name=rsDN.getString(1);
}
...
//结果却出现下列错误提示,
[blue]
Note: sun.tools.javac.Main has been deprecated.
/Home/BaseSet/DeptIndex1.jsp:40: Exception java.sql.SQLException must be
caught, or it must be declared in the throws clause of this method.
rsDN = sqlbean.executeQuery("select top 1 DeptName from Department where DeptID='"+DID+"'");
^
1 error, 1 warning
[/blue]
谁能告诉我,它是怎么了???
 
Exception java.sql.SQLException must becaught, or it must be declared in the throws clause of this method.
我看是异常没有抓吧
try
{

rsDN = sqlbean.executeQuery("select top 1 DeptName from Department where DeptID='"+DID+"'");
}
catch (SQLException E)
{
out.println("SQLException: " + E.getMessage());
out.println("SQLState: " + E.getSQLState());
out.println("VendorError: " + E.getErrorCode());
}
 
函数里面不能用out.println吧?
 
不过我用返回值显示出来:
SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
SQLState: 24000
VendorError: 0
 
sql语句有问题,建议用
select * from Department
测试一下
 
2个错误吧,一个是异常没有Catch,或者没有在函数名后throws,
另一个没见过....,先把异常解决了也许就OK,反正另一个只是警告性错误.
另:为什么不把这些数据操作放到JavaBean里?
 
2个错误吧,一个是异常没有Catch,或者没有在函数名后throws,
另一个没见过....,先把异常解决了也许就OK,反正另一个只是警告性错误.
另:为什么不把这些数据操作放到JavaBean里?

来自:wqhatnet, 时间:2004-4-11 14:05:42, ID:2551989
 
来自:wqhatnet, 时间:2004-4-11 14:05:42, ID:2551989
 
多人接受答案了。
 
后退
顶部