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
Solved

Error unterminated string.

Posted on 2002-05-22
6
529 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
stateless EJB with glassfish 2 73
sortaSum challenge java 17 173
org.apache.jasper.JasperException: using jstl in jsp embedded jetty 13 651
main method of string class 3 117
This article describes how to reset your Windows 10 password when you've forgotten it.
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 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