Display Data from Database in JSP
This is detailed java program to connect java application with mysql database and execute query to display data from the specified table.
Before running this java code you need to copy a mysql connector jar file (mysql-connector-java-3.1.6-bin.jar) in the jdk1.6.0_01\lib and set class path for this jar file.
This is first jsp page that has a link 'show data from table', user can show all the data from table after clicking link. This is the code of first welcome jsp page.
Create a new directory in Tomcat-6.0.16/webapps/ and Save this code with the name "welcome_to_database_query.jsp" in Tomcat-6.0.16/webapps/user along with WEB-INF directory. Start tomcat server and type url 'http://localhost:8080/user/welcome_to_database_query.jsp' in address bar of browser and run.
This page has a link, to show data from the database click on the link that calls another jsp file named ConnectJspToMysql.jsp
ConnectJspToMysql.jsp page creates connection between application and database. In this code connection is between application and table name 'stu_info' in database 'student'.
Save this code with name ConnectJspToMysql.jsp in the same dirctory of welcome_to_database_query.jsp. Click on the link given in the first jsp page,that calls this jsp page and show all data from the table.
Click on the <--back button to go to first page of the application.