楼上没明白我意思。比如说DIM 用INT ,RESPONSE 用<%=%>,其它SET ,CONN都用什么代替。

解决方案 »

  1.   

    对着api 改吧有些东西不一样。
      

  2.   

    你这段代码应该是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();
      

  3.   

    楼上:调试出好多ERROR,我怀疑是不是见了鬼了。asp 好好的。换成jsp就全错。
    ssage Unable to compile class for JSP:description The server encountered an internal error that prevented it from fulfilling this request.exceptionorg.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 line: 18 in the jsp file: /csdnhelp.jsp
    ResultSet cannot be resolved to a type
    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");
    21:  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";
    An error occurred at line: 20 in the jsp file: /csdnhelp.jsp
    DriverManager cannot be resolved
    17:  PreparedStatement prpst=null;
    18:  ResultSet rs=null;
    19:  Class.forName("adodb.connection");
    20:  conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;","sa","105936");
    21:  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";
    22:  prpst=conn.prepareStatement(sql);
    23:  rs=prpst.executeQuery();
    An error occurred at line: 25 in the jsp file: /csdnhelp.jsp
    Dim cannot be resolved to a type
    22:  prpst=conn.prepareStatement(sql);
    23:  rs=prpst.executeQuery();
    24:  if(rs.next()){
    25:  Dim d=new Dim();
    26:  d.setNumberOfXing(rs.getString(1));
    27:  d.setNumberOfMing(rs.getString(2));
    28:  response.getWriter().writer(d);
    An error occurred at line: 25 in the jsp file: /csdnhelp.jsp
    Dim cannot be resolved to a type
    22:  prpst=conn.prepareStatement(sql);
    23:  rs=prpst.executeQuery();
    24:  if(rs.next()){
    25:  Dim d=new Dim();
    26:  d.setNumberOfXing(rs.getString(1));
    27:  d.setNumberOfMing(rs.getString(2));
    28:  response.getWriter().writer(d);
    Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:199)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:475)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:380)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:355)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:342)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    note The full stack trace of the root cause is available in the Apache Tomcat/8.0.5 logs.
      

  4.   

    还有下面我遇到的这个:怎么看都没语法错误啊。换成int x =Integer.parseInt(rs.getString("数字"));也错,他妹妹的。
    escription The server encountered an internal error that prevented it from fulfilling this request.exceptionorg.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 33 in the jsp file: /buffer.jsp
    The method parseInt(String, int) is undefined for the type buffer_jsp
    30:   ResultSet rs=stmt.executeQuery(sql); 
    31: 
    32: 
    33: out.print(parseInt(rs.getString("数字"),10));
    34: 
    35: 
    36: 
    Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:199)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:475)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:380)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:355)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:342)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    note The full stack trace of the root cause is available in the Apache Tomcat/8.0.5 logs.Apache Tomcat/8.0.5
      

  5.   

    这是肯定的啊,ASP和JSP语法方面还是差挺多。
    1.你在JSP页面没有导包。在页面最上面加上<%@page import="java.sql.*"%>
    2.Dim是你自己的对象啊,你也要把那个类import到你的jsp页面。
      

  6.   

    DIM是ASP中定义变量的语句。相当于String,Int之类
    包导入了啊。就是取不了rs中的整型值。不知道怎么回事
      

  7.   

    你上面的那个必须错啊,字符串怎么能转整型呢?转的话肯定是NumFormatException,你数据库是什么类型的字段,你rs取得时候就要怎么取,比如:
    rs.getInt  rs.getString 
    要么你就按索引去,不过还是要清楚类型,不然你接收类型不对还是会报错。
      

  8.   

    看错了,建议你先打印一下rs取出来的值,再转型什么的。看是不是这的问题。还有把那些定义成全局变量,比如conn,rs什么的。jsp定义全局变量要写在<%! %> 这个标签里,相当于声明。
      

  9.   

    Quote: 引用 5 楼 mybluemoon 的回复:

    楼上:调试出好多ERROR,我怀疑是不是见了鬼了。asp 好好的。换成jsp就全错。19:  Class.forName("adodb.connection");你驱动这段代码肯定不对啊,什么数据要对应的驱动