If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Jstl problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-05-07, 08:32
dimis2500 dimis2500 is offline
Registered User
 
Join Date: Jan 2005
Posts: 362
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).
Reply With Quote
  #2 (permalink)  
Old 09-06-07, 02:51
dimis2500 dimis2500 is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On