Solved

Error unterminated string.

Posted on 2002-05-22
6
530 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enabling the Skype for Business Meeting Scheduler in Hybrid OWA
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.

685 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