This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Urgent....

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using the ODBC bridge when you have the Oracle thin drivers set up in your class path? I'm sure that this is or will cause errors.
Replace your Connection code with:

after you get this sorted out, you can then start to debug the errors. I have a feeling that java knows what an Oracle BLOB is, but the ODBC driver your using will probably say "what the heck is this??!".
By the way, you really should look at the Oracle9i JDBC Developer's Guide and Reference which will explain and give examples for programmers from complete newbie to expert.
Jamie
[ November 25, 2003: Message edited by: Jamie Robertson ]
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jyothsna,
Please use meaningful subjects for your posts. You will get more and better responses when people looking through the forum see something that describes the nature of your question. Also, avoid using "Urgent"... it will make many people simply ignore your post which is no more and no less important than anyone else's.
thanks,
bear
 
Their achilles heel is the noogie! Give them noogies tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic