<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
final String dbURL = "jdbc:mysql://localhost:3306/mani";
final String dbUser = "root";
final String dbPass = "";
Connection conn = null; // connection to the database
String message = null; // message will be sent back to client
Blob image = null;
try {
// connects to the database
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn = DriverManager.getConnection(dbURL, dbUser, dbPass);
String sql="select * from tst";
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery(sql);
while(rs.next())
{
image=rs.getBlob("photo");
%>
<%=rs.getString("first_name") %>
image:
<img src="<%=image %>" width="50" height="50"/>
<%
}
}
catch(Exception e)
{
System.out.println(e);
}
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
这个编码没有显示任何错误,但是 不从数据库中检索图像。
但它显示数据库中的first_name列;它只是 未在浏览器中显示的图像。
这里的编码是用JSP页面编写的,我使用MySQL连接器驱动程序将Java编码与JSP连接。