1. Suppose we want to display something from a bean like System.out.println
in the JSP page,
do we have to pass the implicit out object to the bean or which way?
can we invoke a method say.. write() in the JSP page from a bean??
Wouldn't it be better to access this through a bean getter??
I am under the impression that outputting to pages is best kept in JSP NOT
in java code thus reducing coupling between application components.
a jdbc question too..
what exactly is class.forName does....
Upper case Class.forName() -- check JDK API docs for Class
I think it returns an instance of the named class (aka Singleton)
At 03:15 AM 1/4/01 -0800, you wrote:
> In the bean put all the relevant commands in order to open the connection
>with the database. Lets say that you have a method called
>
>public void openConnection()
>{
> try
> {
> // Load the database's drivers.
> Class.forName("database's drivers here");
>
> // Obtain connection with the database.
> Connection dbcon = DriverManager.getConnection("databse address
>here", "username here", "password here");
>
> // create new statemtn here.
> Statement stmt = dbcon.createStatement();
>
> String select = "SELECT * FROM <table name here>";
>
> // get the whole result set
> ResultSet rs = stmt.executeQuery(retrieve);
>
> // go through all rows
> while (rs.next())
> {
> System.out.println(rs.toString());
> }
>
> } // end try
> // If driver not found.
> catch (ClassNotFoundException cnfe)
> {
> System.out.println("Driver not found. " + cnfe);
> }
> catch (SQLException sqle)
> {
> System.out.println("Connection to the database could not be
established.
>" + sqle);
> }
>}
>
>Then define a bean in the jsp page using the <jsp:useBean> tag.
>
> Call the openConnection using the beans reference name (lets say that the
>reference to the bean is called myBean) myBean.openConnection();
>this will open the connection with the database and will display all the
>data in the specified table.
>
> You can have two diffreent methods if you want. One to open the
>copnnection and the other to get the data. You can call them with the same
>way. Do not forget to close the connection with the databse after you
>finish. Use the close() method in order to do it.
>
> Hope this helps.
>
>
>
>
>>From: Deepak Kumar <[EMAIL PROTECTED]>
>>Reply-To: A mailing list about Java Server Pages specification and
>> reference <[EMAIL PROTECTED]>
>>To: [EMAIL PROTECTED]
>>Subject: Executing SQL query in bean
>>Date: Thu, 4 Jan 2001 02:48:54 -0800
>>
>>Hi Friends,
>>
>>I want to write the code of JDBC connectivity in a
>>bean and then use the resultset in JSP page how can i
>>accomplish this.
>>
>>Thanks in advance.
>>Deepak Kumar
>>
>>__________________________________________________
>>Do You Yahoo!?
>>Yahoo! Photos - Share your holiday photos online!
>>http://photos.yahoo.com/
>>
>>==========================================================================
=
>>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
>>JSP-INTEREST".
>>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
>>DIGEST".
>>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 Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
>===========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
>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".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
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".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
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