当前位置: 代码迷 >> J2SE >> 请教为什么出现Syntax error on token(s), misplaced construct(s)错误
  详细解决方案

请教为什么出现Syntax error on token(s), misplaced construct(s)错误

热度:738   发布时间:2016-04-24 15:38:24.0
请问为什么出现Syntax error on token(s), misplaced construct(s)错误
请各位大侠看看我下面的代码,为什么在执行到try的时候就出现标题中的错误


package   db;
import   java.sql.*;
import   java.io.*;
import   javax.servlet.jsp.*;
import   javax.servlet.jsp.tagext.*;
import   java.util.*;
import   java.math.*;
public   class   db   extends   TagSupport
{
  private   String   table;
public   int   doStartTag()   throws   JspTagException
  {

  return(SKIP_BODY);
}
public   int   doEndTag()  
{
        try
        {
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
Connection   conn=DriverManager.getConnection( "jdbc:microsoft:sqlserver://202.112.14.112:1433;DatabaseName=dongshi ", "sa ", "ds ");
Statement   stmt=conn.createStatement();
        ResultSet   rs=stmt.executeQuery( "select   *   from "+table);
while(rs.next())
{
System.out.print(rs.getString( "uid "));
        System.out.print(rs.getString( "pwd "));
        System.out.print(rs.getString( "name "));
        System.out.print(rs.getString( "age "));
}
        //pageContext.getOut().write(table);
        }
        catch
        {
        return   (EVAL_PAGE);

    }
  finally
  {
   
  }
  return   (SKIP_BODY);
}
  public   void   settable(String   table)
  {

  this.table=table;
  }
public   String   gettable(String   table){
return(table);
}
}

------解决方案--------------------
楼主的是自定义标签吧,我不太熟悉,我感觉太麻烦,我一般写的是标签文件,因为不用写标签库描述,我刚刚试了下楼主的代码,扩号好像有问题,代码应该没问题.

package test;

import javax.servlet.Servlet.*;
import java.sql.*;
import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.*;
import java.math.*;


public class test extends TagSupport {
private String table = "emPop ";
public int doStartTag() throws JspTagException {

return (SKIP_BODY);
}

public int doEndTag() {
try {
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").
newInstance();
Connection conn = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=VODDATA ",
"sa ", " ");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "select * from " + table);
while (rs.next()) {
System.out.print(rs.getString( "emPop_id "));
}
//pageContext.getOut().write(table);
} catch (Exception ex) {
return (EVAL_PAGE);

}
return (SKIP_BODY);
}

}
编译通过了的.
  相关解决方案