Link to home
Start Free TrialLog in
Avatar of delphiusr
delphiusr

asked on

parsing a database setting file

Hi!

I would like to know if there is any function or method which I can use to parse my database setting file (ie. database.xml). For example, in my web.xml file I indicated
the following:

  <servlet>
    <servlet-name>database</servlet-name>
    <servlet-class>myproj.servlet.InitServlet </servlet-class>
    <init-param>
      <param-name>database</param-name>
      <param-value>/WEB-INF/database.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

I was overriding the init method of the InitServlet class which extends HttpServlet class. because of the structure of my web.xml file, I could only get the database file which contains the setting, and this is through getInitParameter("database"), so now, how would I be able to parse the web.xml file to set the properties of the data source like setDriverClass and setUrl?

Thanks in advance!

Raymond
Avatar of saxaboo
saxaboo

Hi,

before thinking about parsing a XML file (which is easy), why not trying something like :

<init-param>
     <param-name>database.driver</param-name>
     <param-value>com.my.driver.ClassName</param-value>
</init-param>
<init-param>
     <param-name>database.URL</param-name>
     <param-value>myConnectString</param-value>
</init-param>
<init-param>
     <param-name>database.user</param-name>
     <param-value>scott</param-value>
</init-param>
<init-param>
     <param-name>database.password</param-name>
     <param-value>tiger</param-value>
</init-param>

Pls tell us if it helps. If you really want some XML parsing sample code, we can provide it as well.

-S
Avatar of delphiusr

ASKER

Hi! Thanks for the reply

I would appreciate it if you would post some XML parsing
code, this is because despite the ease of use which you provided in the above code, we were required by our project supervisor to use XML parsing. =)
ASKER CERTIFIED SOLUTION
Avatar of saxaboo
saxaboo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial