Wednesday, February 18, 2009

Referencing the Datasource from the Applcation.

Referencing the Datasoure from the Applcation..



reference the JNDI resource you just configured form the web appllicatoin

To do so

create and entry in the application 's deployment descriptor
(web.xml)



the following to reference the JNDI Datasource in the application's deployment descriptor.

1. In the Projects window, expand the Web Pages > WEB-INF subfolder and double-click web.xml. A graphical editor for the file displays in the Source Editor.




webpage>>>web-INF
webpage>>>web-INF
webpage>>>web-INFwebpage>>>web-INF

webpage>>>web-INF


double click web.xml

double click web.xml


double click web.xml



2. Click the References tab located along the top of the Source Editor. Expand the Resource References heading, then click Add. The Add Resource Reference dialog opens.
3. For Resource Name, enter the resource name that you gave when configuring the JNDI Datasource for the server above (jdbc/IFPWAFCAD). The Description field is optional, but you can enter a human-readable description of the resource, e.g., Database for IFPWAFCAD application. Note that the default resource type is javax.sql.DataSource. Leave all fields that are provided by default and click OK. The new resource is added under the Resource References heading:





Adding the Database Driver's JAR File to the Server

Adding the database driver's JAR file is another step that is vital to enabling the server to communicate with your database. Ordinarily, you would need to locate your database driver's installation directory and copy the mysql-connector-java-5.x-bin.jar file from the driver's root directory into the library folder of the server you are using. Fortunately, the IDE's server management is able to detect at deployment whether the JAR file has been added - and if not, it does so automatically.

In order to demonstrate this, open the Servers window (Choose Tools > Servers). For both GlassFish and Tomcat, the IDE provides a JDBC driver deployment option. If the option is enabled, it initiates a check to determine whether any drivers are required for the server's deployed applications. In the case of MySQL, if the driver is required and it is missing, the IDE's bundled driver is deployed to the appropriate location on the server.


Tomcat

1. Open the Servers window by choosing Tools > Servers from main menu.
2. Select Tomcat 6.0 in the left panel, then click the Deployment tab in the main pane. Notice that the Enable JDBC driver deployment option is selected by default.



# Click the Classes tab. This tab displays all of the JAR files contained in the server's lib folder. If you have already deployed your project to the server, you will find that the mysql-connector-java-5.x-bin.jar file is listed here. If not, click Close to exit the Servers window, and deploy your project now (next step).
# In the Projects window, choose Deploy (or Undeploy and Deploy) from the right-click menu of the project node. You can view progress in the IDE's Output window (Ctrl-4; ⌘-4 on Mac). The output indicates that the MySQL driver is deployed to /lib in the Tomcat server.

JNDI

Setting up a Connection Pool


Database Connection Pooling (DBCP) libraries


Java Naming and Directory Interface (JNDI)

http://java.sun.com/products/jndi/

The Java Naming and Directory Interface (JNDI) is part of the Java platform, providing applications based on Java technology with a unified interface to multiple naming and directory services. You can build powerful and portable directory-enabled applications using this industry standard. » Read More
JNDI and Java EE Technologies
JNDI works in concert with other technologies in the Java Platform, Enterprise Edition (Java EE) to organize and locate components in a distributed computing environment.


commuincation between the server and database is to set up
a database connection pool


database connection pool


creating a new connection for each client request can be very time consuming,
especially for applciatoins that continously receive a large number of request.

tom remedy this..


numerous connections are created and maintaned in a connection tool.

Any incoming requests that requires access to the application's data layer use
an already-created connection from the pool.

Likewise,when a requet is completed, the connection is not close, but return
to the pool.



1. Setting up a JNDI Datasource
2. Referencing the Datasource from the Application
3. Adding the Database Driver's JAR File to the Server



Setting up a JNDI Database

both GlassFish and Tomcat contain Database connection Pooling (DBCP)libraries that proved connction pooling functionality in a way that is transparent toyou as d

developer. In either case, you need to configure a JNDI Datasource for the serverr

that creates an interface withch your applcation ca use for connection pooling
Depending on whether you are using GlassFish or Tomcat,



Any incoming requests that require access to the application's data layer use an already-created connection from the pool.





Tomcat

Configure a JNDI Datasource in Tomcat by adding a declaration for your resource to the application's context.xml file. This is the application's context container, which enables you to specify application meta-data necessary for the server in order to deploy and run the application. There are various locations where you can specify context elements, such as your server's global $CATALINA_HOME/conf/context.xml file. By adding resource declarations to your application's context.xml file however, you limit the resource to that application, and do not need to configure anything within the server itself. For more information, see the Apache Tomcat Configuration Reference.



configure a JNDI Datasource in tomcat by adding a declaration for your
resource to the application's extext.xml


context container.

enable::

specify application meta-data necessary for the sever in order to deploy and run applcation.


From the Projects window, open the application's context container in the Source Editor by double-clicking the Web Pages > META-INF > context.xml file.



Web Pages > META-INF > context.xml file.

Web Pages > META-INF > context.xml file.

Web Pages > META-INF > context.xml file.




Add the following tags (changes below in bold) as a declaration for the JNDI resource:




maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="nbuser" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/MyNewDatabase"/>







maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="nbuser" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/MyNewDatabase"/>








maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="nbuser" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/MyNewDatabase"/>

CSS

style.css

Create a simple stylesheet that enhances the interface display.

1. Right-click the IFPWAFCAD project node in the Projects window and choose New > Other. In the New File wizard, make sure Web is selected under Categories, then choose Cascading Style Sheet and click Next.
2. Type style for CSS File Name and click Finish. The IDE creates an empty CSS file and places it in the same project location as index.jsp and response.jsp. Note that a node for style.css now displays within the project in the Projects window, and the file opens in the Source Editor.
3. In the Source Editor, add the following content to the style.css file:

project1.-2 creating

Preparing the Interface

a simple interface for the 2 pages.

both index.jsp and response.jsp implement an HTML table to display data in a structured fashion.

Index.jsp also requires an HTML form that includes a drop-down list.


index.jsp

make sure index.jsp is opened in the Source Editor.

doulbe click index.jsp


webpage>>index.jsp

ctrl+shift 8


table icon fromt the HTML category and note that the code snippet for the
item displays


* Rows: 2
* Columns: 1
* Border Size: 0






Response.jsp

right-click the IFPWAFCAD project node int he proejcts window and choose

New > JSP.

The New JSP file dialog open


JSP File Name field, enter response, note that Web Pages is currently
selected for the Location field. meaning that the file will be
created in the project's web directory.

This is the same location as where the index.jsp is generated and opens
in the Source Editor.

A new JSP node also displays under Web Pages in the Projects window



Shift +F6

project 1-2 Creatig a New Project

Creatig a New Project

The applcation enable a user to choose a counseling subject from a drop-down list
(index.jsp),

then retrieves data from the MySQL database and returns the information to the
user(response.jsp)


Creating a new project in the Netbean

1. Ctrl+Shift+N

2. Project Name:: IFPWAFCAD

3. chose server..

project 1-planning

project 1-planning



I can make web application which is simple ...

So..a two tier architecture would be fantastic for this job..

what is this talking about.

So the applcation communicates directly with a data source using the Java Database Connectivity API.

JDBC::java Database Connectivity


Webserver using JDBC > indext.Jsp <---- response.jsp

Database Server sujbect Counselor




Two tier architecture can be easily mapped to a client -server configuration
where a user's brower servers as the client.
and a remote database reachable over the Internet corresponsd the server.



I have to create 2 javaServer Pages.

// basic HTML to implement a simple interface, followed by SQL tags
provide by JSTL technology in order to query the databse. Consdier the
following client server sna


The welcome page(index.jsp) presents the user wiht a simple HTML form.
When a client requests the index.jsp page, the JSP code contained therein parsed.
and data form the Sujbect database table is gathered, add to the page,and sent to the client.

The uer makes a slection on the provide HTML form and submit, which causese theclient to make a request for response.JSP

When response.jsp is parsed, dta from both the Subject and Counselor table is
gathered and isertd into the page.
the page is reutrend to the client and the use rviews data based upon his or her
selection

Project 1

Project 1

Creating a Simple Web Application Using a MySQL Database

create a simple web application that connects to a MySQL database server.


including.

s JavaServer Pages (JSP), JavaServer Pages Standard Tag Library (JSTL),
the Java Database Connectivity (JDBC) API, and two-tier, client-server architecture




MySQL is a open source database management systme

using in web applications

why: speed, flexiblity and reliablity.



MySQL employ SQL (structured query language)

for what?

Accessing and processing data in database.

::

If I want to accessing and processing data in database, What do I have to look
I have used the MySQl. because this can manage the data.
Why do we chose MySQl because We love to use it for it's fliexiblity and reliablity and speed. and also it is open source.


To do this project

We need database

and

table :: Subject and Counselor.

database:: MyNewDatabase




Contents

Content on this page applies to NetBeans IDE 6.x

* Planning the Structure
* Creating a New Project
* Preparing the Interface
* Setting up a Connection Pool
o Setting up a JNDI Datasource
o Referencing the Datasource from the Application
o Adding the Database Driver's JAR File to the Server
* Adding Dynamic Logic
o Adding the JSTL Library to the Project's Classpath
o Adding taglib Directives to the JSP Pages
o Adding JSP and JSTL Code
* Deploying and Running the Project



software that required to finished this project

Software or Resource Version Required
NetBeans IDE version 6.x Java
Java Development Kit (JDK) version 5 or 6
MySQL database server version 5.x
MySQL Connector/J JDBC Driver version 5.x
GlassFish application server
or
Tomcat servlet container V2 UR2 or V3 Prelude

version 6.x

class schedule

related and more advanced tutorials, see the following resources:

* Creating a Simple Web Application Using a MySQL Database.

A follow-up tutorial demonstrating how to created a simple two-tiered web application in the IDE using the MySQL database you just created.


* Building Relationships Between Rails Models.

A document describing how to build relationships (one-to-one and one-to-many) between models using a MySQL database in a NetBeans Ruby on Rails project.


* Connecting to Databases.


A basic guide to connecting to databases in NetBeans IDE.

Topic that covers for mysql

ntents

Content on this page applies to NetBeans IDE 6.1

* Configuring MySQL Server Properties
* Starting the MySQL Server
* Creating and Connecting to the Database
* Creating Database Tables
* Working with Table Data
* Running an SQL Script

managing mySQL -with netbean IDE 6.5

http://www.netbeans.org/kb/61/ide/mysql.html

managing mysql connection is pain in web development process,

however, with Netbean IDE,

It can be done alot easier and faster with windows evironment to contorl mysql

able to bring up the other sql file

run the database

connecting mysql database

creating table.

adding column table

inserting

select queriey


it is same thing as dos command but it make much more easier to do with.