Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to establish a database connection using JSP

In this post you will learn how to Establish a Database connection using JSP.The first thing you need to add is a page directive to import the java.sql package for the database code as follows:

You'll use a single ResultSet object to hold your database results. Because you'd like this to be
available to the entire page, the next thing you do is declare it in a JSP declaration tag:

Finally, you establish a connection to the database and retrieve the required data.
Now i will show you a complete code for simple application to connect database.





Employee Details







try {
Class.forName("org.gjt.mm.mysql.Driver");
Connection db = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/quoting");
Statement s = db.createStatement();
rs = s.executeQuery("select * from employee");
}
catch (Exception e) {
// For now, just report the error to the system log
System.out.println(e.toString());
}
%>














Employee Details





Employees



try {
while (rs.next()) {
%>








}
}
catch (SQLException e) {
// For now, just report the error to the system log
System.out.println(e.toString());
}
%>

&action=edit">
edit


&action=delete">
delete




New Employee






Output:



This post first appeared on Learnprogramingbyluckysir, please read the originial post: here

Share the post

How to establish a database connection using JSP

×

Subscribe to Learnprogramingbyluckysir

Get updates delivered right to your inbox!

Thank you for your subscription

×