Desculpem o mau jeito mas a minha paciência está quase no fim...
Estou testando alguns exemplos para fazer inserção/recuperação de
arquivos binários (imagens) no Oracle usando Java.
Alguém sabe fazer isso?
De qualquer modo, agradeço qualquer ajuda, insentivo, consolo ou
mensagem de apoio ...
Um abraço e muito obrigado!
O problema é o seguinte:
Criei uma tabela a ser acessada no sqlplus com o comando: "create table
media (name varchar2(200), data blob);"
Abaixo está o código java que estou testando.
Logo depois a mensagem de erro que obtenho ao tentar compilar.
/**************O CÓDIGO**********************
import java.sql.*;
import java.io.*;
import java.util.*;
import oracle.jdbc.driver.*;
public class BlobInsert {
Connection conn;
Statement stmt;
ResultSet rs;
int bufferSize;
public BlobInsert() throws SQLException{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@192.168.100.5:1521:quiz","clube", "clube000");
stmt = conn.createStatement();
}
public void sendToDB(){
String pathname, name;
int amount = 0;
OutputStream out = null;
BufferedInputStream in = null;
// escolhe o arquivo
pathname = "/tmp/";
name ="code.gif";
try{
file://conn.setAutoCommit(false);
stmt.executeUpdate("insert into media (name, data) values ('" + name +
"', empty_blob())");
System.out.println("Antes do update).");
rs = stmt.executeQuery("select data from media where
name='code.gif'");
System.out.println("Depois do update).");
if (rs.next()){
BLOB blob = ((OracleResultSet)rs).getBLOB(1);
out = ((oracle.sql.BLOB)blob).getBinaryOutputStream();
bufferSize = ((oracle.sql.BLOB)blob).getBufferSize();
in = new BufferedInputStream( new FileInputStream(pathname+name),
bufferSize );
byte[] b = new byte[bufferSize];
int count = in.read(b, 0, bufferSize);
while (count != -1){
out.write (b, 0, count);
amount += count;
System.out.println("Processed " + amount + " bytes.");
count = in.read(b, 0, bufferSize);
}
System.out.println("Processed " + amount + " bytes. Finished.");
out.close();
out = null;
in.close();
in = null;
conn.commit();
}//de if
System.out.println("Passei por fora!");
} file://de try
catch (Exception e) {
e.printStackTrace();
}
}//de sendToDB
public static void main(String[] args){
try{
BlobInsert w = new BlobInsert();
w.sendToDB();
}
catch(Exception e){
e.printStackTrace();
}
}//de main
}//de BlobInsert
****************FIM DO CÓDIGO******************/
Tenho obtido o seguinte erro:
**********ERROS***********
<root@/../>javac BlobInsert.java
...
BlobInsert.java:0: The method oracle.jdbc2.Clob getClob(java.lang.String)
declared in interface oracle.jdbc.OracleResultSet cannot override the method
of the same signature declared in interface java.sql.ResultSet. They must
have the same
return type.
import java.sql.*;
^
BlobInsert.java:38: Class BLOB not found.
BLOB blob = ((OracleResultSet)rs).getBLOB(1);
^
<root@/../>
***********FIM DOS ERROS**********
------------------------------ LISTA SOUJAVA ----------------------------
http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP
dúvidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
para sair da lista: envie email para [EMAIL PROTECTED]
-------------------------------------------------------------------------