
hello friends
can anyone help me..
I have to make a project to make Identity card for employees...but i am facing problems with database and jsp connection ...
also tell me how to retrive data such as name and image at a paticular place on the I-card...plz reply as soon as possible....
Thank you in advance
Rohan

Here is a jsp code that retrieves the name and image from the database and display it in the html table.
1)data.jsp:
<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<HTML>
<table border="1">
<tr><th>Name</th><th>Address</th><th>Image</th></tr>
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement stmt=con.createStatement();
String strQuery = "select * from data";
ResultSet rs = stmt.executeQuery(strQuery);
while(rs.next()){
%>
<tr>
<td><%=rs.getString("name")%></td><td><%=rs.getString("address")%></td>
<td align="center">
<img src="image.jsp?imgid=<%=rs.getInt(1)%>" width="50" height="50">
</a></td>
</tr>
<%
}
rs.close();
con.close();
stmt.close();
}
catch(Exception e)
{
e.getMessage();
}
%>
</table>
</HTML>
2)image.jsp:
<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<%
int id = Integer.parseInt(request.getParameter("imgid"));
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
String strQuery = "select image from data where id="+id;
ResultSet rs = st.executeQuery(strQuery);
String imgLen="";
if(rs.next()){
imgLen = rs.getString(1);
}
rs = st.executeQuery(strQuery);
if(rs.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
st.close();
response.reset();
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();
}
}
catch (Exception e){
e.printStackTrace();
}
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.