首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

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

2014-01-26 
为什么在执行到try的时候就出现Syntax error on token(s), misplaced construct(s)错误 package db import

为什么在执行到try的时候就出现Syntax error on token(s), misplaced construct(s)错误


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 "));         

热点排行