關於jsp連線mysql資料庫顯示圖片,老師無能,不會教人,求大神賜教
圖片選擇部分:
<%@ page contentType=“text/html; charset=utf-8” language=“java” import=“java.sql.*” errorPage="" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + “?/”
+ request.getServerName() + “:” + request.getServerPort()
+ path + “/”;
%>
相片id
資料庫連線部分:
<%@ page contentType=“text/html; charset=utf-8” language=“java” import=“java.sql.*” errorPage="" %>
<%@ page import=“java.sql."%>
<%@ page import="java.util.”%>
<%@ page import=“java.io.*”%>
System.out.println("連線成功"); ResultSet rs = stmt.executeQuery(sql1); rs.last(); int ID = rs.getInt("ID") + 1; String sql = "insert into tupian(ID,tupianid,photo) values(" + ID + ",?,?)"; PreparedStatement pstmt = conn4.getConnection().prepareStatement( sql); pstmt.setString(1, tupianid); long l = (long) str.available(); pstmt.setBinaryStream(2, str, l); //out.print(bi.available()); try { pstmt.executeUpdate(); } catch (Exception e) { //out.print(sql); out.print(e.getMessage()); } out.println("Success,You Have Insert an Image Successfully"); %>
以下是java部分
package com.conDBMS;
import java.sql.Connection;
import java.sql.DriverManager;
public class Conn {
final String MYSQLDBDRIVER = “com.mysql.jdbc.Driver”;
final String MYSQLDBURL = “jdbc:mysql://localhost/user”;
final String MYSQLDBUSER = “root”;
final String MYSQLDBUSERPASS = “root”;
public Connection getConnection() { try { Class.forName(MYSQLDBDRIVER); Connection con = DriverManager.getConnection(MYSQLDBURL, MYSQLDBUSER, MYSQLDBUSERPASS); return con; } catch (Exception e) { e.printStackTrace(); return null; } }
}
以下是網頁提示錯誤,不知道哪裡出了問題!
HTTP Status 500 - /image.jsp (line: 16, column: 0) The value for the useBean class attribute com.conDBMS.conn is invalid.
type Exception report
message /image.jsp (line: 16, column: 0) The value for the useBean class attribute com.conDBMS.conn is invalid.
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /image.jsp (line: 16, column: 0) The value for the useBean class attribute com.conDBMS.conn is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:275)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:107)
org.apache.jasper.compiler.GeneratorUseBean.accept(Node.java:1178)
org.apache.jasper.compiler.NodeVisitor.visitBody(Node.java:2428)
org.apache.jasper.compiler.NodeRoot.accept(Node.java:464)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
org.apache.jasper.compiler.Generator.generate(Generator.java:3646)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:250)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.30 log