> Why DataBase Connections are not written directly in
> JSP?
Are you asking why connections aren't coded onto each JSP ? If that is the case I would suggest you think about if you have 50 pages and you have to change 1 thing in your connection that would require 50 corrections which are both time consuming and error prone. If that isn't what you are asking please clarify
*Note* This is my personal take on things not guaranteed to be right, but the way I would interpret it.
see u can write the database connections in jsp ,no problem.But generally developers dont write because the it will not be good practice.
Instead of writing in jsp,we will write a class which consists of the some static methods,in which we write the code to connect to the database.
Cheers
Sudha.
or we setup a datasource in the webserver and let it connect to the database, then use a simple JNDI lookup to fetch such a connection. But then we would still NOT do any database transactions in JSP's, simple because it goes against everything that is object oriented. If you put your database code into seperate classes you can use it wherever you like, if you put it directly in your JSP's you need to copy it, which brings up the horrible maintenance problem that aknibbs described.
If you use beans to do your database access you also gain in reusability.
I have a multitude of beans that I wrote to do database access stuff for some website B2B applications.... A little while later I had to write some client order entry utilities that utilized Swing, and guess what? All I had to do was reuse my same beans for 80% of the code.