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

Discussion in 'Java' started by Hugh Mandeville, Jul 21, 2005.

  1. Hi,
    >From a JSP page (Tomcat 5.0.28), 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
     
    Hugh Mandeville, Jul 21, 2005
    #1
    1. Advertising

  2. Hugh  Mandeville

    shakah Guest

    Hugh Mandeville wrote:
    > Hi,
    > >From a JSP page (Tomcat 5.0.28), 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>
     
    shakah, Jul 21, 2005
    #2
    1. Advertising

  3. 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>
     
    Hugh Mandeville, Jul 21, 2005
    #3
  4. Hugh  Mandeville

    shakah Guest

    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?
     
    shakah, Jul 21, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Mark Bram

    Custom JSTL that accepts JSTL expression

    Robert Mark Bram, Dec 15, 2004, in forum: Java
    Replies:
    0
    Views:
    1,000
    Robert Mark Bram
    Dec 15, 2004
  2. Anonymous
    Replies:
    0
    Views:
    1,532
    Anonymous
    Oct 13, 2005
  3. DaFoot
    Replies:
    1
    Views:
    1,732
    DaFoot
    Oct 23, 2008
  4. Pius
    Replies:
    0
    Views:
    399
  5. David Morel
    Replies:
    1
    Views:
    103
Loading...

Share This Page