jsp编程从数据库中取出
1、读取数据testimageoutjsp文件
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="javasql" %>
<%@ page import="javautil" %>
<%@ page import="javatext" %>
<%@ page import="javaio" %>
<html>
<body>
<%
ClassforName("sunjdbcodbcJdbcOdbcDriver");
Connection con=DriverManagergetConnection("jdbc:odbc:denglu","sa","sa");
Statement stmt=concreateStatement();
ResultSet rs=null;
int id=IntegerparseInt(requestgetParameter("id"));
String sql = "select image from picturenews where id='"+id+"'";
rs=stmtexecuteQuery(sql);
while(rsnext())
{
ServletOutputStream sout = responsegetOutputStream();
InputStream in = rsgetBinaryStream(1);
byte b[] = new byte[0x7a120];
for(int i = inread(b);i!=-1)
{
soutwrite(b);
inread(b);
}
soutflush();
soutclose();
}
%>
<body>
</html>
2、取出所要显示的showimagejsp文件
<%@ page contentType="text/html;charset=bg2312"%>
<%@ page import="javasql" %>
<html>
<head>
<title>显示数据库测试页</title>
</head>
<body>
<%
ClassforName("sunjdbcodbcJdbcOdbcDriver");
Connection con=DriverManagergetConnection("jdbc:odbc:denglu","sa","sa");
Statement stmt=concreateStatement();
String sql=new String();
sql = "select id from picturenews";
ResultSet rs=stmtexecuteQuery(sql);
//显示最后一条记录的
rslast();
%>
<table>
<tr><td><img src='testimageoutjspid=<%=rsgetInt("id")%>'></td></tr>
</table>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)