Results 1 to 5 of 5
  1. #1
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default JSP "else" syntax error with html

    i am trying to checking the connection status of my java code with mysql DB the it showing this error (Syntax error on token "else", delete this token)
    Please Help !
    Thanks

    Java Code:
    <h1 class='text-center'>Welcome </h1>
            
            
            
            <%! ResultSet rst; %>
            
             
            <% try { 
          
              Class.forName("com.mysql.jdbc.Driver");
              Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306:demo?useSSL=false","root","password");
              PreparedStatement pst=con.prepareStatement("select * from data");
              ResultSet rst=pst.executeQuery();
              
               
    
              %>
               
              
             <%  if (con != null){             
                       out.println("<h1>Connected</h1>") ;
                        }%>
                 <% else {            
             out.println("<h1>Not Connected</h1>") ;
               } %>
    i want html code like <h1>Connected</h1> not with "out.println"
    Last edited by vknehra10; 07-11-2018 at 06:08 AM.

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    390
    Rep Power
    4

    Default Re: JSP "else" syntax error with html

    if (){} else {} have to be in the same html/JSP tag.
    No catch statement for your connection?

  3. #3
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: JSP "else" syntax error with html

    catch statement is in last

    if i write if and else in same jsp tag , then where i put the html code if "if statement" will be correct ?

  4. #4
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    390
    Rep Power
    4

    Default Re: JSP "else" syntax error with html

    write a complete Java code that covers each outcome and then surround it with the tags.

  5. #5
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: JSP "else" syntax error with html

    ok will try
    Thanks benji2505

Similar Threads

  1. newbie need help with query result in List
    By aliaj00 in forum Hibernate
    Replies: 3
    Last Post: 12-11-2014, 10:47 AM
  2. where to put the result of query?
    By wiz6 in forum Java Servlet
    Replies: 2
    Last Post: 07-17-2013, 11:08 AM
  3. Using jTable to display query result
    By zenith666 in forum New To Java
    Replies: 2
    Last Post: 01-13-2012, 02:29 AM
  4. column result query
    By vikashkumar in forum JDBC
    Replies: 0
    Last Post: 04-03-2009, 02:23 PM
  5. Help!! how to turn query result to string
    By stefanybaez in forum Advanced Java
    Replies: 2
    Last Post: 12-11-2008, 11:42 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •