coder4lyf
coder4lyf

Reputation: 927

JSP function error

I'm new to JSP and I'm trying to write a function that executes a query and then returns the metadata. I'm getting an error that reads: Generated servlet error: Syntax error on token ")", Block expected after this token

Here is my code:

<%! ResultSetMetaData test(ResultSet rs, Statement s){
  try{
  rs = s.executeQuery("SELECT * FROM students WHERE name = 'Alice Wood'");
  }
  catch(SQLException e);

  return rs.getMetaData();
}

%>

Upvotes: 0

Views: 252

Answers (1)

Shota
Shota

Reputation: 7340

Firstly you should not write your Java code in JSP file, especially SQL queries, you should do it in your Servlet.

Secondly you used declaration tag: <%! %> which is suitable only for declarations, you need Scriptlet tag here: <% your code here %>, but as I said it is not good too, at least you should transfer your code into Servlet.

Here is good tutorial for JSP tags and overall about JSP: http://www.tutorialspoint.com/jsp/jsp_syntax.htm

Upvotes: 2

Related Questions