You may use a format as follows:

file.ini
-----------
driver=namedriver
db=namedb
.....

this is the classical format of a properties file.
Than you just open a stream to that file and use the load function of a java.util.
Propeties object to load the whole file.
than do something like:

name=prop.getProperty("db");
driver=prop.getProperty("driver");

Example:

java.io.FileInputStream is = null;
 java.util.Properties p = new java.util.Properties();
 String propertiesFilename = "settings.ini";
 try {
  is = new java.io.FileInputStream(propertiesFilename);
  p.clear(); // not realy necessary
  p.load(is);
  //System.out.println("pr:" + Prop.properties.toString());
 } catch (java.io.IOException ioex) {
  System.out.println("Can't read the settings file");
 } catch (Exception ex) {
  ex.printStackTrace();
 } finally {
  if (is != null) {
   try {
    is.close();
   } catch (java.io.IOException ioex1) {
    ioex1.printStackTrace();
   }
   is = null;
  }
 }

than
even you use an: Enumeration e = p.keys();
or simply get a value of a property as I have shown you above.

Ciao,
Ionel Condor.



Xing guohong wrote:

> Hi,
>     You can creat a jsp file, and define the url, username, password
> variables in it. In the JSP or other files need to connect to DB include it.
> I think it is faster than reding files to get the string before connect to
> DB.
>     For example:
>     1.db.jsp
> <%!
>     String m_url = "jdbc:oracle:thin:@hostname:1521:servicename"
>     String m_username = "scott";
>     String m_password = "tiger";
> %>
>     2.a.jsp includes db.jsp
> <%@ page language="java" %>
> <%@ include file="db.jsp"%>
> xgh
> ----- Original Message -----
> From: "Ritu Kama" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, July 28, 2000 3:19 PM
> Subject: Can I read a text file thru a bean
>
> > Hi all,
> >
> > My requirement is as follows:
> >
> > I have a initialization file containing the database name.
> > Thru my bean I want to read the DB name and establish connection with that
> > particular database. I don't want to hardcode the db name.
> >
> > Please suggest how to achieve this.
> >
> > Thanks
> > Ritu
> >
> >
> ===========================================================================
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> > Some relevant FAQs on JSP/Servlets can be found at:
> >
> >  http://java.sun.com/products/jsp/faq.html
> >  http://www.esperanto.org.nz/jsp/jspfaq.html
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to