Solved

Error unterminated string.

Posted on 2002-05-22
6
524 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

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

Ramani
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 50 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now