Solved

Error unterminated string.

Posted on 2002-05-22
6
528 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
As a business owner, there are many things that keep you up at night. Profit margins, employee retention, human resource protocols, whether your product or service will remain competitive. When you own or manage a technology company that operates la…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

803 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