Results 1 to 2 of 2

Thread: Jstl problem

  1. #1
    Join Date
    Jan 2005
    Posts
    362

    Unanswered: Jstl problem

    I use jstl tag library to connect at H2 database at a jsp file.
    I want to find the path of the database dynamically (or to be related, not absolute path).
    I write this

    Code:
    <sql:setDataSource url="jdbc:h2:"+context.getRealPath("/DB/db")+"""
                     driver="org.h2.Driver"
                       user="SA" password=""/>
    but there is an error.
    How can I make the setdatasource to have a related file?
    I tried this also
    Code:
    <sql:setDataSource url="jdbc:h2:/DB/db"
                     driver="org.h2.Driver"
                       user="SA" password=""/>

    and it did not work.
    The relative path of the db is DB (folder) / db (database).

  2. #2
    Join Date
    Jan 2005
    Posts
    362
    I found this solution that works.
    Code:
    <% ServletContext context = session.getServletContext();
    String realContextPath = context.getRealPath("\\DB\\db");%>
    <sql:setDataSource url="<%="jdbc:h2:"+ realContextPath%>"
                     driver="org.h2.Driver"
                       user="SA" password=""/>
    Dimis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •