asp 转成JSP 怎么写?大侠们指点
set conn=server.CreateObject("adodb.connection")
Conn.Open "PROVIDER=SQLOLEDB;DATA SOURCE=(local/SQLEXPRESS:1433);UID=sa;PWD=123456;DATABASE=name"
server.createobject("adodb.recordset")
set rs1=conn.execute("select sum(姓数字) as 姓数字,sum(名数字) as 名数字 from (select '姓数字'=数字, '名数字 '=0 from name.dbo.table1 WHERE 汉字 = '"+textXing+"' UNION select '姓数字'=0, '名数字'= 数字 from name.dbo.table1 WHERE 汉字='"+textMing+"' )aa" )
Dim numberOfXing=rs1("姓数字")
Dim numberOfMing=rs1("名数字")
response.Write(numberOfXing)
response.Write(numberOfMing)
rs1.close
set rs1=nothing
------解决方案-------------------- rs1 = null;
------解决方案-------------------- 对着api 改吧有些东西不一样。
------解决方案-------------------- 你这段代码应该是Odbc访问数据库的吧,换成Jdbc就行了。大致试着改一下,具体细节你再调试(默认给你写到一个servlet的doPost方法里,因为看你用到了HttpResponse对象):
Connection conn=null;
PreparedStatement prpst=null;
ResultSet rs=null;
Class.forName("adodb.connection");
conn=DriverManager.getConnection("这里的url你参考一下SQLOLEDB文档的格式","sa","123456");
String sql="select sum(姓数字) as 姓数字,sum(名数字) as 名数字 from (select '姓数字'=数字, '名数字 '=0 from name.dbo.table1 WHERE 汉字 = '"+textXing+"' UNION select '姓数字'=0, '名数字'= 数字 from name.dbo.table1 WHERE 汉字='"+textMing+"' )aa";
prpst=conn.prepareStatement(sql);
rs=prpst.executeQuery();
if(rs.next()){
Dim d=new Dim();
d.setNumberOfXing(rs.getString(1));
d.setNumberOfMing(rs.getString(2));
response.getWriter().writer(d);
}
conn.close();
prpst.close();
rs.close();
------解决方案-------------------- 引用: 楼上:调试出好多ERROR,我怀疑是不是见了鬼了。asp 好好的。换成jsp就全错。
ssage Unable to compile class for JSP:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException : Unable to compile class for JSP:
An error occurred at line: 16 in the jsp file: /csdnhelp.jsp
Connection cannot be resolved to a type
13: String textXing="张";
14: String textMing="秋";
15:
16: Connection conn=null;
17: PreparedStatement prpst=null;
18: ResultSet rs=null;
19: Class.forName("adodb.connection");
An error occurred at line: 17 in the jsp file: /csdnhelp.jsp
PreparedStatement cannot be resolved to a type
14: String textMing="秋";
15:
16: Connection conn=null;
17: PreparedStatement prpst=null;
18: ResultSet rs=null;
19: Class.forName("adodb.connection");
20: conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;","sa","105936");
An error occurred at l