Toon posts:

[JSP] Image in een Oracle Database opslaan

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik wil met een JSP pagina plaatjes opslaan in een Oracle database.
In de database heb ik een tabel met alleen een TESTID(char) en een PIC(blob).

Hoe kan ik met een jsp pagina een image in die database gooien.

Ik heb het volgende, maar het wil niet echt werken.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<%@ page import ="java.sql.*, java.io.*, java.util.Vector" %>
<html>
<head><title>Untitled Document</title></head>

<body>

<%!
        public void insertPic (String [] args) throws IOException {
                Connection con;
                Statement stmt;
                PreparedStatement pstmt;
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                ObjectOutput out = new ObjectOutputStream(outStream);
                out.writeObject(request.getParameter("PIC"));
                ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
                try{
                    Class.forName("org.gjt.mm.mysql.Driver");
                }
                catch(java.lang.ClassNotFoundException e){
                    e.printStackTrace();
                }
                try{
                    con = DriverManager.getConnection("jdbc:odbc:Oracle", "sveneh", "dutch");
                    pstmt = con.prepareStatement("insert into test1 (TESTID,PIC) values (request.getParameter("TESTID")));
                    pstmt.setBinaryStream(1,inStream,inStream.available());
                    pstmt.executeUpdate();
                    System.out.println("Successfully Uploaded");
                }catch(SQLException esql){
                    esql.printStackTrace();
                }
} %>
<form method="post" action="uppic3.jsp" name="form1" enctype="multipart/form-data">
  <table align="center">
    <tr valign="baseline"> 
      <td nowrap align="right">TESTID:</td>
      <td> <input type="text" name="TESTID" value="" size="32"> </td>
    </tr>
    <tr valign="baseline"> 
      <td nowrap align="right">PIC:</td>
      <td> <input type="file" name="PIC" value="" size="32"> </td>
    </tr>
    <tr valign="baseline"> 
      <td nowrap align="right">&nbsp;</td>
      <td> <input type="submit" value="Insert Record"> </td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>

  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 12:00

Janoz

Moderator Devschuur®

!litemod

Kijk ff in de quickstart. Het is niet de bedoeling om een berg code te posten met alleen een "Hij doet ut nie" erbij.

maw.. Geef eens iets meer info...

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'