Java J2ee Tutorials

Retrieve Data Using JSP MySQL

Saturday, January 14, 2012

viewRecords.jsp
<%@ page language = "java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import = "java.sql.*"%>
View Records
<%
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost/test_db";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "";

%>
<%
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url, userName, password);
String sql = "SELECT * FROM EMP_DETAIL ORDER BY EMP_ID ASC";
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
//out.println(rs.getInt(1) +" : "+rs.getString(2) +"
");
int tID = rs.getInt(1);
int empID = rs.getInt(2);
String empName = rs.getString(3);
//out.print(" | ");
//out.println(rs.getString(2));
%>
<%
}
con.close();
//out.println("Data inserted");
%>
<%=empID%><%=empName%>Edit Delete

Free Career Predictions

1 comments:

sunitha said...

select PASSWORD from login where USERNAME=?
how to retrieve data for this query using jsp

Post a Comment