Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Connecting to MySQL database and retrieving and displaying data in JSP page

Connecting to MySQL database and retrieving and displaying data in JSP page Connecting to MySQL database and retrieving and displaying data in JSP page This tutorial shows you how to connect to MySQL database and retrieve the data from the

Tutorial Details:

database. In this example we will use tomcat version 4.0.3 to run our web application.
Creating Table in the database.
Using a JDBC driver
org.gjt.mm.mysql.Driver Driver to connect to the database.
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connecting to your database
Structuring statements
Executing Query and Processing result set
<%@ page language="java" import="java.sql.*"%>

Read from mySQL Database


Following records are selected from the 'jakartaproject' table.
 










<%
String DRIVER = "org.gjt.mm.mysql.Driver";
Class.forName(DRIVER).newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
try{
String url="jdbc:mysql://192.168.10.2/tutorial?user=tutorial&password=tutorial";
int i=1;
con=DriverManager.getConnection(url);
stmt=con.createStatement();
rst=stmt.executeQuery("select * from jakartaproject ");
while(rst.next()){
if (i==(i/2)*2){
%>






<%
}else{
%>






<% }
i++;
}
rst.close();
stmt.close();
con.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
%>

Sr.
No.
Project Url
Address
Description
of the project
<%=i%> . <%=rst.getString(2)%> <%=rst.getString(3)%>   <%=rst.getString(4)%>
<%=i%> . <%=rst.getString(2)%> <%=rst.getString(3)%>   <%=rst.getString(4)%>





Deploying web application
Testing Application
Out Put of the application
Resources
http://www.mysql.com
MySQL Database download and related resource.
http://java.sun.com/products/jdbc/index.html
Sun Microsystems. JDBC Data Access API
http://java.sun.com/products/jdbc/articles.html
Articles and tutorials
http://industry.java.sun.com/products/jdbc/drivers
List of available Latest Database Drivers for different database.


 

Rate Tutorial:
http://www.roseindia.net/mysql/mysqldatabase.shtml

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Connecting to MySQL database and retrieving and displaying data in JSP page

View Tutorial:
Connecting to MySQL database and retrieving and displaying data in JSP page

Related Tutorials:

Get disconnected with CachedRowSet , This allows for ResultSet s to be serialized, sent to remote clients, updated
The new J2EE RowSet implementation provides updateable disconnected ResultSets in your JSPs
 
Develop Java portlets
Develop Java portlets
 
SQL Database Access with DBTags
SQL Database Access with DBTags In a J2SE or J2EE application, Java Database Connectivity (JDBC) can be used to create a connection with a SQL database, create database tables, retrieve result sets, and update the database. To use a database from a Jav
 
Using CachedRowSet to Transfer JDBC Query Results Between Classes
Using CachedRowSet to Transfer JDBC Query Results Between Classes The Java Database Connectivity (JDBC) API provides developers with an interface to a SQL database server, such as MySQL or Oracle. Central to any JDBC application is the java.sql.ResultS
 
An Introduction to Java Object Persistence with EJB
The 'impedance mismatch' between relational databases' tabular orientation and object-oriented Java's hierarchical one is a perennial problem for which the Java world has several good solution offerings. This article, the first in a three-part series, wil
 
Jeff Schmitt's JDBC Page
This tutorial assumes you are using the MySQL database and the GWE JDBC drivers. The host computer is triton.towson.edu.
 
Introduction to JSP
Introduction to JSP Introduction to JSP Java Server Pages or JSP for short is Sun's solution for developing dynamic web sites. JSP provide excellent server side scripting support for creating database driven web applications. JSP enable the
 
Backing Up and Restoring A MySQL Database
Backing Up and Restoring A MySQL Database Backing Up and Restoring A MySQL Database This tutorial explains the how to backup and restore the MySQL Database. Databases are used to store large amount of precious data and it becomes very important to
 
First Step towards JDBC!
First Step towards JDBC! First Step towards JDBC Introduction T his article introduce you with JDBC and shows you how to create a database application to access the databases. For the shake of simplicity, in very first example Access database and
 
First Step towards JDBC!
First Step towards JDBC! Welcome to our JDBC Section First Step towards JDBC This article introduce you with JDBC and shows you how to create a database application to access the databases. Accessing the Database from Servlet This article shows
 
Reading Request Information
Reading Request Information Retrieving the data posted to a JSP file from HTML file Now I will show you how to retrieve the data posted from a HTML file in a JSP page. Consider an html page that prompts the user to enter his/her name, let's call
 
Introduction to the JSP Java Server Pages
Introduction to the JSP Java Server Pages Welcome to JSP Section Introduction To JSP Java Server Pages or JSP for short is Sun's solution for developing dynamic web sites. JSP provide excellent server side scripting support for creating database
 
JSP FUNDAMENTALS
JSP FUNDAMENTALS JSP FUNDAMENTALS By: Hrishikesh Deshpande Introduction : JSP termed as Java Server Pages is a technology introduced by Sun Microsystems Inc. to develop the web application in more efficient way than Servlets. It has got many
 
Using Beans in JSP. A brief introduction to JSP and Java Beans.
Using Beans in JSP. A brief introduction to JSP and Java Beans. USING BEANS IN JSP Java Beans Java Beans are reusable components. They are used to separate Business logic from the Presentation logic. Internally, a bean is just an instance of a
 
Welcome to the MySQL Tutorials
Welcome to the MySQL Tutorials Welcome to the MySQL Tutorials Using MYSQL Database This lesson is intended to provide hands an experience with MYSQL database Backing Up and Restoring A MySQL Database In this lession you will learn how to take
 
Using MYSQL Database with JSP & Servlets.
Using MYSQL Database with JSP & Servlets. Using MYSQL Database with JSP & Servlets. MY SQL is a powerful RDBMS, which can handle large amount of data. And more interestingly it is free to use, except for some commercial use. you can download it
 
Connecting to MySQL database and retrieving and displaying data in JSP page
Connecting to MySQL database and retrieving and displaying data in JSP page Connecting to MySQL database and retrieving and displaying data in JSP page This tutorial shows you how to connect to MySQL database and retrieve the data from the
 
Connecting to the Database Using JDBC and Pure Java driver
Connecting to the Database Using JDBC and Pure Java driver Connecting to the Database JDBC Driver In our search engine we are using MySQL database server and MM.MySQL Driver for connecting our application to the database. MM.MySQL Driver is
 
Building Search Engine Applications Using Servlets !
Building Search Engine Applications Using Servlets ! Building Search Engine Applications Using Servlets Please visit http://www.webappcabaret.com/javadevelopers/search to see running copy of our search engine. Introduction This tutorial takes
 
Struts Guide
Struts Guide Struts Guide This tutorial is extensive guide to the Struts Framework. In this tutorial you will learn how to develop robust application using Jakarta Struts Framework. This tutorial assumes that the reader is familiar with the web
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.