0

unable to compile jsp in netbeans with glass fish server3.1.2,it is showing the following exception

org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

PWC6197: An error occurred at line: 9 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
';' expected

PWC6197: An error occurred at line: 9 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
';' expected

PWC6197: An error occurred at line: 9 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
not a statement

PWC6197: An error occurred at line: 9 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
';' expected

my java and jsp code

<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@page language="java" import= "java.sql.*"%>
<%
String driver="org.postgresql.Driver";
Class.forName(driver).newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
try
{
  String url="jdbc:postgresql://localhost:5432/ksa?user="postgres"password="postgres"";
  con=DriverManager.getConnection("url");
  stmt=con.createStatement();
}          
catch(Exception e)
               {
  System.out.println(e.getMessage());
       }
if(request.getParameter("action")!=null)
       {
           String name=request.getParameter("name");
           String address=request.getParameter("address");
           String id=request.getParameter("id");
           stmt.executeUpdate("insert into cd values('"+ name +"','"+ address +"')");
           rst=stmt.executeQuery("select * from cd");             
       }    
%>

netbeans shows the error in the line

String url="jdbc:postgresql://localhost:5432/ksa?user="postgres"password="postgres"";

iam using postgresql9.1,the glassfish log shows the following

SEVERE: Error compiling file: /home/adapco/.netbeans/7.1.1/config/GF3_1/domain1  /generated/jsp/cddata/org/apache/jsp/index_jsp.java
WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
ksa
  • 311
  • 1
  • 10
  • 29
  • Just one (unrelated) warning: `stmt.executeUpdate("insert into cd values('"+ name +"','"+ address +"')");` is a classic example of a [SQL injection vulnerability](http://en.wikipedia.org/wiki/SQL_injection), so make sure you don't use it in production... – beny23 Apr 17 '12 at 10:33
  • @beny:any alternate solutions to overcome this problem – ksa Apr 17 '12 at 10:48
  • That's a different question, but essentially you should be using prepared statements with bind variables. – beny23 Apr 17 '12 at 11:52
  • There's plenty on SO with regard to SQL injection, for example http://stackoverflow.com/questions/1582161/how-does-a-preparedstatement-avoid-or-prevent-sql-injection – beny23 Apr 17 '12 at 11:59

2 Answers2

0

That line is incorrect:

String url="jdbc:postgresql://localhost:5432/ksa?user="postgres"password="postgres";

It should be:

String url="jdbc:postgresql://localhost:5432/ksa?user=\"postgres\"&password=\"postgres\"";

Update:

By the way:

con=DriverManager.getConnection("url");

should be:

con=DriverManager.getConnection(url);
Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79
0

I think it's a small wrong,your '{' and '}' don't match,and i met the same question.