Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / February 2005

Tip: Looking for answers? Try searching our database.

White space problems

Thread view: 
C - 09 Feb 2005 09:20 GMT
I'm trying to display the rows of a sql database in a web page, but the row
called "Bedlington station",
having a space in, is causing problems. How do I fix this? I've tried
enclosing single quotes in the double quotes,
and using \" also tried %20 but nothing works. Any ideas?

code:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
  <sql:query var="queryresults" dataSource="jdbc/poolDB">
   SELECT * FROM x31
 </sql:query>
<html>
   <head><title>JSP Page</title></head>
   <body>

       <table border=1>
     <tr>
 <th>Arrive</th>
     </tr>
     <c:forEach var="row" items="${queryresults.rows}">
 <tr>
     <td><c:out value="${row.NORCAT}" /></td>
   //  <td><c:out value="${row.Bedlington Station}" /></td>
 </tr>
     </c:forEach>
     </table>

   </body>
</html>
Robert Klemme - 09 Feb 2005 09:41 GMT
> I'm trying to display the rows of a sql database in a web page, but the row
> called "Bedlington station",
[quoted text clipped - 28 lines]
>     </body>
> </html>

I'm not too familiar with the std taglib but a solution that would
definitely work is to rename columns.  You can use something like "select
NORCAT, [Bedlington Station] as BS FROM x31" and then use BS instead of
the other name.  Or you use numeric indexing for the columns.

Regards

   robert
Karsten Baumgarten - 09 Feb 2005 09:42 GMT
> I'm trying to display the rows of a sql database in a web page, but the row
> called "Bedlington station",
> having a space in, is causing problems. How do I fix this? I've tried
> enclosing single quotes in the double quotes,
> and using \" also tried %20 but nothing works. Any ideas?
[code.snip]

How about renaming the column?

Signature

Regards,

Karsten

C - 09 Feb 2005 09:57 GMT
I want users to be able to input place names, and then do a check against
the DB, so I don't really want to do that.

>> I'm trying to display the rows of a sql database in a web page, but the
>> row
[quoted text clipped - 5 lines]
>
> How about renaming the column?
Lee Fesperman - 09 Feb 2005 22:53 GMT
> I want users to be able to input place names, and then do a check against
> the DB, so I don't really want to do that.

Sounds like your database structure is badly designed. You really shouldn't be using
place names as column names.

Care to post your DDL?

Signature

Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS  (http://www.firstsql.com)

dar7yl - 10 Feb 2005 00:27 GMT
> I'm trying to display the rows of a sql database in a web page, but the
> row
> called "Bedlington station",
> having a space in, is causing problems. How do I fix this? I've tried
> enclosing single quotes in the double quotes,
> and using \" also tried %20 but nothing works. Any ideas?

The SQL language supports backtick ( ` )
as the delimeter for column names
ie, SELECT `Bedlington station` FROM ....

But, I agree with a previous poster,
you should try to normalize your database
so that your columns are data-independant.

for instance
   SELECT * FROM table
       WHERE station='Bedlington station'
#notice the single tick ' this time

regards,
   Dar7yl
Lee Fesperman - 10 Feb 2005 02:22 GMT
> > I'm trying to display the rows of a sql database in a web page, but the
> > row
[quoted text clipped - 6 lines]
> as the delimeter for column names
> ie, SELECT `Bedlington station` FROM ....

Standard SQL uses double quotes (") rather than backtick. See the first page of the SQL
Tutorial at http://www.firstsql.com/tutor.htm.

Signature

Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS  (http://www.firstsql.com)

dar7yl - 10 Feb 2005 11:02 GMT
>> > I'm trying to display the rows of a sql database in a web page, but the
>> > row called "Bedlington station",
[quoted text clipped - 9 lines]
> page of the SQL
> Tutorial at http://www.firstsql.com/tutor.htm.

You are correct.  I was, of course referring to MySQL, which does extend
SQL a wee bit.

regards,
   Dar7yl
C - 10 Feb 2005 23:47 GMT
Thanks for all the replies,
I found the answer was in fact:
Bedlington%station

>>> > I'm trying to display the rows of a sql database in a web page, but
>>> > the
[quoted text clipped - 16 lines]
> regards,
>    Dar7yl


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.