Hi Everybody...
Please ignore my previous query... help me out in this...
My Code:
///////////////////////////////////////////////////
// PicLoader
//
// Read and write pictures to Oracle as BLOBs.
//
//
///////////////////////////////////////////////////
import java.io.*;
import java.util.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
public class PicLoader {
static
String sqlOut=
" begin"+
" insert into pic_store(description,picture)"+
" values(?,empty_blob())"+
" return picture into ?;"+
" end;";
static String sqlIn=
"select picture from pic_store where description=?";
static String sqlOut1=
" insert into pic_store(description,picture)"+
" values(?,empty_blob())";
String cs="jdbc
dbc:aprta";
String user="rta";
String passwd="oracle";
Connection con;
void connect() {
try
{
System.out.println("Registering driver");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println("Exception in forName try block " + e);
}
try {
System.out.println("getting connection");
con=DriverManager.getConnection(cs,user,passwd);
System.out.println("connection success");
}/* catch(Exception e) {
System.err.println("********** Could not connect to Oracle.");
System.exit(1);
} */
catch(SQLException sqle)
{System.out.println("error is "+sqle);}
}
void disconnect() {
try {
if (con != null) con.close();
}catch(Exception e){e.printStackTrace();}
}
public void write(String desc) throws Exception
{
System.out.println("going to try connecting");
if (con == null) connect();
System.out.println("going to commit false");
con.setAutoCommit(false);
System.out.println("going to prepare call"+sqlOut);
CallableStatement stmt=con.prepareCall(sqlOut);
System.out.println("going to set string "+stmt);
stmt.setString(1,desc);
System.out.println("going to register parameters");
stmt.registerOutParameter(2,java.sql.Types.BLOB);
System.out.println("going to execute "+stmt);
stmt.executeUpdate();
// get stream to Oracle
System.out.println("going to getblob");
BLOB blob=(BLOB) stmt.getBlob(2);
System.out.println("orastrm");
OutputStream orastrm=blob.getBinaryOutputStream();
// load picture from local filesystem
System.out.println("filebuffer");
BufferedInputStream filebuf=new BufferedInputStream(new FileInputStream(desc+".jpg"));
// send data to Oracle
System.out.println("writing to database");
int i;
while((i=filebuf.read())!=-1)
orastrm.write(i);
System.out.println("written");
con.commit();
// cleanup
filebuf.close();
orastrm.close();
stmt.close();
disconnect();
}
public byte[] read(String desc) throws Exception
{
if (con == null) connect();
PreparedStatement stmt=con.prepareStatement(sqlIn);
stmt.setString(1,desc);
ResultSet rs=stmt.executeQuery();
rs.next();
Blob picBlob=rs.getBlob(1);
byte[] picBuf = picBlob.getBytes(1,(int) picBlob.length());
stmt.close();
disconnect();
return picBuf;
}
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Usage:
java PicDisp <description>");
System.exit(1);
}
System.out.println("going to try writing");
try {
(new PicLoader()).write(args[0]);
} catch(Exception e){e.printStackTrace();}
}
}
////////////////////////////////////////////////////////////////////////
at the command prompt I am running the program like this,
cmd prompt>java PicLoader sound1
where sound1 is an image file(jpg format) and I am getting the following Exception... can someone solve this for me..
regards
Jyothsna