Originally posted by Tom Katz:
ONE APPROACH MIGHT BE... err, excuse me
One approach might be to store the Connection object as a Session object, which you can then access in other JSPs/Servlets.
Yes why not. But it is extremely EXTREMELY poor practice to place the connection object into session.
Let me know if you understand this.
Originally posted by an indian:
why dont you use a servlet to do the database operations and then pass the data to the JSP using setAttribute.
Better. But DB connections should not be handled in JSP neither in servlets. Its better to use a plain normal/regular java class for db operations.
System.out.println("A SQL error is generated :"+e);
As far as displaying it in the JSP the possibilities are almost limitless. What you really have to figure out is do you want the data in a simple <table> format or do you wish to display it in a form type layout. Each has obvious differences and different implementation details. i.e. to use a table you could use a method I will call toHTMLTable like below:
This will take a ResultSet, iterate over each row and append the data onto a StringBuffer. You could then easily use this in a JSP page with the <%= somename.toHTMLTable() %> where the table will be printed to the browser window.
The form on the other hand would be quite different since it would likely requrie only single entries from the query to be displayed in individual text fields. This is also relatively simple with calls like:
Where these will be called in the JSP page with simple:
I hope this helps in some way.
Originally posted by Surya Vamshi:
cAN ANY BODY TELL ME HOW TO FETCH DATA FROM DATABASE TABLE USING JDBC AND PRESENTING TO JSP.
iS IT OK TO PROVIDE THE JDBC CONNECTION DETAILS IN JSP. ONCE THE CONNECTION HAS BEEN ESTABLISHED HOW TO PRESENT DATA IN JSP
hear is answer
<%@ page language="java" info="this is answer page" import="java.io.*,java.sql.*" %>
Connection con=DriverManager.getConnection("jdbc dbc:","username","password");
ResultSet rs=st.executeQuery("select * from emp");