employee_list.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
 <HEAD><TITLE>Employee List</TITLE></HEAD>
 <BODY>
 <%@ page import="java.sql.*" %>

<%@ page import="java.lang.ClassNotFoundException" %>


<% 
Statement st = null;
ResultSet rs = null;
Connection conn = null;

try {
    Class.forName("com.mysql.jdbc.Driver");
    conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+"Hibernate MySQL","root","root");

     st = conn.createStatement();
     rs = st.executeQuery("select * from employees");
    while(rs.next()) {
%><TABLE BORDER=1 width="75%">
<TR><TH>Last Name</TH><TH>First Name</TH></TR>

<TR><TD><%= rs.getString("lname_txt") %></TD>
<TD><%= rs.getString("fname_txt") %></TD></TR>
<%
     }
%>
</TABLE>
<%
}  catch (Exception ex) {
    out.println("Error :" + ex);
    %>


<%
    }  finally {
    if (rs != null) rs.close();
    if (st != null) st.close();
    if (conn != null) conn.close();
    }
%>
</BODY>
</HTML>




Database name: Hibernate MySQL  Table: employees

+--------------+-----------+------+-----+---------+-------+
| Field        | Type      | Null | Key | Default | Extra |
+--------------+-----------+------+-----+---------+-------+
| lname_txt    | char(50)  | YES  |     | NULL    |       |
| fname_txt    | char(50)  | YES  |     | NULL    |       |
| employee_num | int(11)   | NO   | PRI |         |       |
| address1_txt | char(120) | YES  |     | NULL    |       |
| address2_txt | char(120) | YES  |     | NULL    |       |
| city         | char(50)  | YES  |     | NULL    |       |
| state        | char(2)   | YES  |     | NULL    |       |
| zip          | char(10)  | YES  |     | NULL    |       |
| phone        | char(14)  | YES  |     | NULL    |       |
+--------------+-----------+------+-----+---------+-------+





Error :java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Hello I try to execute the above coding i am getting Error :java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

i am using eclipse,tomcat and mysql i cant able to retrive the datas from the table through jsp gudie me to solve the problem

thanks in advance

have a nice time

It appears you don't have the JAR file in short a library file which has to be part of your project.

Download The JAR File From Here or even from another link of your choice.

After Downloading it to your HD, attach it to your project.

NetBeans Procedure:

Right Click on Project;

Add JAR/Folder;

Hope this helps you.

I'm gone be rude and say: Why the hell you want to use Hibernate if you still place database connectivity code into JSP instead of Java class where it bellongs? Learn first proper MVC approach and add new frameworks

Ganges , I Have already provided you with the help above.

As far as your code is concerned, well, servlets were invented in java for one purpose. That is to separate code from presentation.

This Click Here is a tutorial on how to make use of servlets. The code also fullfills 2 functionalities:

Login,

Viewing Profile Details.

Please Try it out.

peter_budo
the database name is HibernateMyQL here i am not using hibernate
i want to know why i am getting the error not your advice.
any how thanks for your comment

As error mention you are missing driver library.

hi peter_budo
i have already installed the library file "mysql-connector-java-5.0.8-bin.jar" and all essential library files even tough i am getting the error so that have posted this query to find solution.

thanking you.
have a nice time

This JAR should be only placed inside your project lib folder(TOMCAT_DIR/webapps/PROJECT_NAME/WEB-INF/lib) if it should be available only to this project. The library can be also placed in Tomcat lib folder (TOMCAT_DIR/lib) and in that case any project that runs on the server can use it. However you should NEVER have this JAR in both locations and you should NEVER add this JAR to JAVA_HOME lib folder as some stupid individuals suggest on the internet. Why not JAVA_HOME lib folder? Because you should never add anything to your Java installation folder and secondly once you want to share project with someone you most likely forget to add this library to your project when you passing in the person with whom you want to share it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.