Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Using JSTL SQL how to get value of PostgreSQL's type INET?

Reply
Thread Tools

Using JSTL SQL how to get value of PostgreSQL's type INET?

 
 
Hugh Mandeville
Guest
Posts: n/a
 
      07-20-2005
Hi,
>From a JSP page (Tomcat 5.0.2, when I try to get the values of an

INET column, it returns empty string. If I do the same select from
psql, it shows the values.

Is there something I have to do in JSP to get the inet value?

I have a simple table in PostgreSQL 7.4.7 that contains a column named
"ip_address" of type "INET".

PostgreSQL Table

Column | Typ | Modifiers

-------------+----------+-----------------------------------------------------
id | integer | not null default
nextval('public.host_id_seq'::text)
ip_address | inet |


Results of Select in pgsql

# select id, ip_address from host;
id | ip_address
----+------------
1 | 127.0.0.1
2 | 127.0.0.1
(2 rows)


JSP Script

<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
<head>
<title>Test JSTL, SQL and PostgreSQL's INET type.</title>
</head>
<body>
<sql:query var="rs" dataSource="jdbc/postgres">
SELECT id, ip_address
FROM host
</sql:query>

Row Count = ${rs.rowCount}<p>

<c:forEach var="row" items="${rs.rows}">
id = ${row.id}, ip_address = ${row.ip_address}<br>
</c:forEach>
</body>
</html>


JSP Output

Row Count = 2
id = 1, ip_address =
id = 2, ip_address =

I have no problem getting columns of other types, like character,
integer, or timestamp. It is only with inet.
Thanks -Hugh

 
Reply With Quote
 
 
 
 
shakah
Guest
Posts: n/a
 
      07-21-2005
Hugh Mandeville wrote:
> Hi,
> >From a JSP page (Tomcat 5.0.2, when I try to get the values of an

> INET column, it returns empty string. If I do the same select from
> psql, it shows the values.
>
> Is there something I have to do in JSP to get the inet value?
>
> [...(good) example snipped...]
>


Can you get what you want if you cast the ip_address in the JSP query,
e.g.:

<sql:query var="rs" dataSource="jdbc/postgres">
SELECT id, CAST(ip_address AS varchar)
FROM host
</sql:query>

 
Reply With Quote
 
 
 
 
Hugh Mandeville
Guest
Posts: n/a
 
      07-21-2005
Thanks for the help. Casting inet to varchar returns the IP address
with a trailing '/32' (space) '127.0.0.1/32', so I added trim as well.

<sql:query var="rs" dataSource="jdbc/postgres">
SELECT id, TRIM(TRAILING '/32' FROM CAST (ip_address as varchar))
AS ip_address
FROM host
</sql:query>

 
Reply With Quote
 
shakah
Guest
Posts: n/a
 
      07-21-2005
Hugh Mandeville wrote:
> Thanks for the help. Casting inet to varchar returns the IP address
> with a trailing '/32' (space) '127.0.0.1/32', so I added trim as well.
>
> <sql:query var="rs" dataSource="jdbc/postgres">
> SELECT id, TRIM(TRAILING '/32' FROM CAST (ip_address as varchar))
> AS ip_address
> FROM host
> </sql:query>


Going a bit off-topic here, but I'm currently evaluating Postgres
(8.0.3) on 64-bit Linux. Do you have any information/opinions/warnings
re using Postgres?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"raise (type, value, traceback)" and "raise type, value, traceback" Jack Bates Python 0 05-02-2011 05:23 PM
(struts/JSTL) Setting bean property value with jstl choose compoundresults DaFoot Java 1 10-23-2008 12:42 PM
Build dynamic sql query for JSTL <sql:query> Anonymous Java 0 10-13-2005 10:01 PM
Custom JSTL that accepts JSTL expression Robert Mark Bram Java 0 12-15-2004 12:26 AM
using param or out tag inside sql tag (jsp/jstl/tomcat) shahbaz Java 0 10-27-2003 02:46 AM



Advertisments