Re: [Can I read a text file thru a bean]

2000-07-30 Thread Hitesh panchal

hi
 ritu

   u can achieve this..
but u mention that u don`t wnat to hard code this then u will write the
database name into file by anoher jsp and read that or u get it from session
or application etc make it clear...

panchal hitesh
(India)



Ritu Kama <[EMAIL PROTECTED]> wrote:
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



Get free email and a permanent address at http://www.netaddress.com/?N=1

===
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



Re: Can I read a text file thru a bean

2000-07-28 Thread Ionel Condor

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



Re: Can I read a text file thru a bean

2000-07-28 Thread Geert Van Damme

well, just read the text file ;-)
However, you might want to store more than just the database name. Maybe you
also want to put other connection parameters like userid, servername,
password there. Or parameters for several databases.
In that case consider using a Properties object. This has methods (store and
load I think) that read and write all the properties to a file in an INI
file format.

Geert Van Damme

> -Original Message-
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Ritu Kama
> Sent: vrijdag 28 juli 2000 9:19
> To: [EMAIL PROTECTED]
> 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



Re: Can I read a text file thru a bean

2000-07-28 Thread Peter Sönnergren

Ritu Kama wrote:
>
> 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.
>

have a servlet that reads the configfile at servletengine startup
(specified in web.xml for tomcat),  have that servlet read the config
variables into public static variables

eg:

class ConfigServlet {
public static String dbDriver;
public static String dbName;

init () {
read variables from configfile


}


class TheBean {

Class.forName(ConfigServlet.dbDriver);
Connection con =
DriverManager.getConnection(ConfigServlet.dbName,"", "");
and so on...

}

this is how i did it, comments are welcome

//peter

--
/**
 *peter sönnergren consultant
 *i n t e r b i z z   s c a n d i n a v i a   a b
 *   http://www.interbizz.com
 */

===
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



Re: Can I read a text file thru a bean

2000-07-28 Thread Peter Sönnergren

Ritu Kama wrote:
>
> 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.
>

have a servlet that reads the configfile at servletengine startup,  have
that servlet read the config variables into public static variables

eg:

class ConfigServlet {
public static String dbDriver;
public static String dbName;

init () {
read variables from configfile


}


class TheBean {

Class.forName(ConfigServlet.dbDriver);
Connection con = DriverManager.getConnection(ConfigServlet.dbName,"",
"");
and so on...

}

this is how i did it, comments are welcome

//peter
--
/**
 *peter sönnergren consultant
 *i n t e r b i z z   s c a n d i n a v i a   a b
 *   http://www.interbizz.com
 */

===
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



Re: Can I read a text file thru a bean

2000-07-28 Thread Xing guohong

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



Can I read a text file thru a bean

2000-07-28 Thread Ritu Kama

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