Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error unterminated string.

Posted on 2002-05-22
6
Medium Priority
?
544 Views
Last Modified: 2010-04-01
I have a page address.jsp. I am posting the code here. The action from this page is sent to add_res.jsp. In the add_res.jsp i do a insert into a access database. I get a unterminated string error
Full compiler error(s):
C:\bea\wlserver6.1\config\mydomain\applications\DefaultWebApp\WEB-INF\_tmp_war_myserver_myserver_DefaultWebApp\jsp_servlet\_database\__add_res.java:127: unclosed string literal
                rs1 = db.execSQL(("INSERT INTO abook (id, uid, fname, lname, tel, fax, email, //[ /database/add_res.jsp; Line: 37]
                                  ^
C:\bea\wlserver6.1\config\mydomain\applications\DefaultWebApp\WEB-INF\_tmp_war_myserver_myserver_DefaultWebApp\jsp_servlet\_database\__add_res.java:128: unclosed character literal
                addr, company, comment) VALUES (NULL, '" + uid + "', '" + fname + "', '" + //[ /database/add_res.jsp; Line: 38]
                                                      ^
C:\bea\wlserver6.1\config\mydomain\applications\DefaultWebApp\WEB-INF\_tmp_war_myserver_myserver_DefaultWebApp\jsp_servlet\_database\__add_res.java:130: ')' expected
                "', '" + company + "', '" + comment + "')")) ; //[ /database/add_res.jsp; Line: 40]
                                                             ^



Code for address.jsp
<html>
<head>
<basefont face="Arial">
</head>

<body>
<center>
<h2>Add Address Book Entry</h2>

<table border=0 cellspacing=5 cellpadding=5>
<form action="add_res.jsp" method="POST">

<tr>
<td><b>Username</b></td>
<td>
<select name="uid">
<!-- generate list of available usernames from database -->
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="db" scope="request" class="Database.DbBean" />

<jsp:setProperty name="db" property="*" />

 <%!  
         ResultSet rs,rs1 = null ;
         ResultSetMetaData rsmd = null ;
         
           String UId;

 
%>
<%

      db.connect();

try {
         
          rs1 = db.execSQL("SELECT uid FROM abook");
         
      // get and display each record
            while(rs1.next())
            {
                   UId = rs1.getString("uid");

                  out.println("<option>" + UId);
            }

      }catch(SQLException e) {
              throw new ServletException("Your query is not working", e);        
              }  
      

      %>
<%
 db.close();
%>

</select>
</td>
</tr>

<tr>
<td>First name</td>
<td><input type="Text" name="fname" size="15"></td>
</tr>

<tr>
<td>Last name</td>
<td><input type="Text" name="lname" size="15"></td>
</tr>

<tr>
<td>Address</td>
<td><textarea name="address"></textarea></td>
</tr>

<tr>
<td>Tel</td>
<td><input type="Text" name="tel" size="10"></td>
</tr>

<tr>
<td>Fax</td>
<td><input type="Text" name="fax" size="10"></td>
</tr>

<tr>
<td>Email address</td>
<td><input type="Text" name="email" size="10"></td>
</tr>

<tr>
<td>Company</td>
<td><input type="Text" name="company" size="25"></td>
</tr>

<tr>
<td>Comment</td>
<td><input type="Text" name="comment" size="25"></td>
</tr>

<tr>
<td colspan=2><input type="submit" name="submit" value="Add"></td>
</tr>
</form>
</table>

</center>
</body>
</html>
The code where the error is add_res.jsp
<html>
<head>
<basefont face="Arial">
</head>
<body>
<center>

<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="db" scope="request" class="Database.DbBean" />

<jsp:setProperty name="db" property="*" />

 <%!  
         ResultSet rs1 = null ;
         ResultSetMetaData rsmd = null ;
       
 
%>
<%
// add_res.jsp

// form data
String uid = request.getParameter("uid");
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String addr = request.getParameter("address");
String tel = request.getParameter("tel");
String fax = request.getParameter("fax");
String email = request.getParameter("email");
String company = request.getParameter("company");
String comment = request.getParameter("comment");

db.connect();

try {
         
          rs1 = db.execSQL("INSERT INTO abook (id, uid, fname, lname, tel, fax, email,
addr, company, comment) VALUES (NULL, '" + uid + "', '" + fname + "', '" +
lname + "', '" + tel + "', '" + fax + "', '" + email + "', '" + addr +
"', '" + company + "', '" + comment + "')") ;


      if(rs1 != null)
      {
      out.println("Entry succesfully added.");
      }
      else
      {
      out.println("Error! Please try again.");
      }
   }
catch(SQLException e) {
              throw new ServletException("Your query is not working", e);        
              }  

db.close();

%>

</center>
</body>
</html>
0
Comment
Question by:ramani081399
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 7027910
I can't tell if it is just because EE word-wrapped your code, but you have a line-break in your SQL above just after email, ... if this is how it is in your code too, you will either have to remove the line break, or break the line into separate strings like this:  (please EE, don't word-wrap this!)

   rs1 = db.execSQL("INSERT INTO abook (id, uid, fname, lname, tel, fax, email, addr, company, comment) " +
                    "VALUES (NULL, '" + uid + "', '" + fname + "', '" + lname + "', '" + tel + "', '" + fax + "', '" + email + "', '" + addr +
                    "', '" + company + "', '" + comment + "')") ;

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 7027912
DOH!   my code was word-wrapped in exactly the most confusing place!  
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 7027917
or:


         rs1 = db.execSQL("INSERT INTO abook (id, uid, fname, lname, tel, fax, email, " +
addr, company, comment) VALUES (NULL, '" + uid + "', '" + fname + "', '" +
lname + "', '" + tel + "', '" + fax + "', '" + email + "', '" + addr +
"', '" + company + "', '" + comment + "')") ;

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:ramani081399
ID: 7028081
Knight,
  I still get the same error.

Ramani
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 200 total points
ID: 7028244
for clarity, you may want to build your SQL in a separate string:


String sql = "INSERT INTO abook (id,uid,fname,lname,tel,fax,email,addr,company,comment)" +
             "VALUES (NULL, '" + uid + "','" + fname + "','" + lname + "','" + tel + "','" +
              fax + "','" + email + "','" + addr + "','" + company + "','" + comment + "')";

rs1 = db.execSQL(sql) ;

0
 

Author Comment

by:ramani081399
ID: 7028268
Thanks it worked
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question