<%@ page contentType="text/html; charset=gb2312" language="java" %> <%@ page import="java.sql.*,javax.sql.DataSource,javax.naming.*,java.io.*" %>
<% java.sql.Connection conn; //java.lang.String strConn; java.sql.PreparedStatement preparedStmt; java.sql.ResultSet sqlRst;
try { //javax.naming.InitialContext ctx = new javax.naming.InitialContext(); //javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:/comp/env/jdbc/myoracle"); //conn = ds.getConnection(); try { Class.forName("oracle.jdbc.driver.OracleDriver");//.newInstance(); }catch(ClassNotFoundException e) { System.err.print("ClassNotFoundException"); } String url="jdbc:oracle:thin:@localhost:1521:eBiz"; //其中eBiz为SID String uid="hr"; String pwd="hr"; conn = DriverManager.getConnection(url,uid,pwd);
String filelocation = request.getParameter("file_name"); File files = new File(filelocation); FileInputStream fis = new FileInputStream(files);
preparedStmt = conn.prepareStatement("INSERT INTO pictures(pic_name,data) VALUES(?,?)"); preparedStmt.setString(1,request.getParameter("pic_name")); preparedStmt.setBinaryStream(2, fis, (int)files.length()); preparedStmt.executeUpdate();
fis.close(); preparedStmt.close(); conn.close(); out.println("操作成功!");
} catch (java.sql.SQLException e) { out.println(e.toString()); } %>
######################################################################################## <%@ page contentType="text/html; charset=gb2312" import="java.sql.*,java.io.*" %> <html> <head><title>Show Pictures</title></head> <body bgcolor="#FFFFFF" text="#000000"> <table> <% int i=1; while (i<3) { String srcstring="http://localhost:8080"+ request.getContextPath()+"/showImage?photo_name="+ Integer.toString(i) %>