Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Sybase jConnect error message loading a BLOB into the database

4 posts in JConnect version 3.0 Last posting was on 1999-02-23 13:01:48.0Z
Werner Ramaekers Posted on 1999-01-07 19:25:19.0Z
Message-ID: <36950A1F.16FA5821@ping.be>
Date: Thu, 07 Jan 1999 20:25:19 +0100
From: Werner Ramaekers <werner.ramaekers@ping.be>
Organization: JSE
X-Mailer: Mozilla 4.5 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Subject: Sybase jConnect error message loading a BLOB into the database
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jconnect40,sybase.public.jconnect30
Lines: 168
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jconnect40:230 sybase.public.jconnect30:1699
Article PK: 256519

Hi,

I'm using Sybase Adaptive Server Anywhere 6.0 and I'm trying to load an
image into the database using Sybase's jConnect jdbc driver.
I've succesfully created the following table in the database :
<quote>
createString = "create table IMAGES " +
"(ID int, " +
"IM image) ";
</quote>

However if I want to insert an image into the database using the source
attached below i get the following error :
C:\ddisk\Java\Projects\Jimi\Demo>java SybaseDbJimiDemoApp
Reading File: dilbert.gif from local filesystem


****Now inserting a blob****

Executing insert #images values(1, ?)

Exception occurred during event dispatching:
java.lang.ClassCastException: java.io.FileInputStream
at
com.sybase.tds.TdsDataOutputStream.dataTypeInfo(TdsDataOutputStream.j
ava)
at com.sybase.tds.DataFormat.<init>(DataFormat.java)
at com.sybase.tds.TdsParam.makeFormat(TdsParam.java)
at com.sybase.jdbc.ParamManager.makeFormats(Compiled Code)
at com.sybase.tds.ParamFormatToken.<init>(ParamFormatToken.java)
at com.sybase.tds.Tds.sendParamStream(Tds.java)
at com.sybase.tds.Tds.language(Tds.java)
at com.sybase.jdbc.SybStatement.sendQuery(SybStatement.java)
at com.sybase.jdbc.SybStatement.execute(SybStatement.java)
at
com.sybase.jdbc.SybPreparedStatement.execute(SybPreparedStatement.jav
a)
at
SybaseDbJimiDemoApp.btnStore_actionPerformed(SybaseDbJimiDemoApp.java
:126)
at
SybaseDbJimiDemoApp$SybaseDbJimiDemoApp_btnStore_actionAdapter.action
Performed(SybaseDbJimiDemoApp.java:166)
at java.awt.Button.processActionEvent(Button.java:256)
at java.awt.Button.processEvent(Button.java:229)
at java.awt.Component.dispatchEventImpl(Compiled Code)
at java.awt.Component.dispatchEvent(Compiled Code)
at java.awt.EventDispatchThread.run(Compiled Code)

This is the source code of SybaseDbJimiDemoApp:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import com.sybase.utils.Debug;

public class SybaseDbJimiDemoApp extends Frame {

Label lblMain = new Label("Status :");
TextField fileName = new TextField("dilbert.gif");
Label fileLabel = new Label("FileName");
Button retrieveButton = new Button("Retrieve from db");
Button storeButton = new Button("Store in db");
String insertQuery = "insert #images values(1, ?)";
String selectQuery = "select img from #images where id=1";


public SybaseDbJimiDemoApp() {
setTitle("Db JIMI Demo App");

Panel p = new Panel();
p.setLayout(new FlowLayout());
retrieveButton.addActionListener(new
SybaseDbJimiDemoApp_btnRetrieve_actionAdapter(this));
p.add(retrieveButton);
storeButton.addActionListener(new
SybaseDbJimiDemoApp_btnStore_actionAdapter(this));
p.add(storeButton);

Panel p1 = new Panel();
p1.setLayout(new FlowLayout());
p1.add(lblMain);

Panel p2 = new Panel();
p2.setLayout(new BorderLayout());
p2.add(p, BorderLayout.NORTH);
p2.add(p1, BorderLayout.SOUTH);

add(p2, BorderLayout.SOUTH);

fileName.setEditable(false);
p = new Panel();
p.setLayout(new FlowLayout());
p.add(fileLabel);
p.add(fileName);
add(p, BorderLayout.NORTH);

try {
DriverManager.registerDriver (new com.sybase.jdbc.SybDriver());
} catch(Exception e) {
System.err.println(e.getMessage());
}

}

void btnRetrieve_actionPerformed(ActionEvent e) {
// btnRetrieve event Handler.
//
// ** This is where the code that retrieves an image from the
database
// ** and puts it in a local file
//
// (Later !)
//



}

void btnStore_actionPerformed(ActionEvent e) {
// btnStore event Handler.
//
// ** This is where the code that reads a local file into
// ** the Database goes: (This is where the important code is)
//
try {
Connection conn = DriverManager.getConnection
("jdbc:sybase:Tds:10.125.16.113:2638", "dba", "sql");


java.io.File fd = new java.io.File(fileName.getText());
java.io.InputStream instream = new java.io.FileInputStream(fd);
System.out.println ("Reading File: " +fileName.getText()
+ " from local filesystem \n");

Statement stmt= conn.createStatement();
stmt.executeUpdate("set textsize 100000");

PreparedStatement pstmt =
conn.prepareStatement(insertQuery );

System.out.println("\n****Now inserting a blob****\n");
System.out.println("Executing " + insertQuery + "\n" );

pstmt.setBinaryStream(1, instream, (int)instream.available());
pstmt.execute();
pstmt.close();


} catch (java.sql.SQLException se) {
System.err.println ("Caught SQL Exception\n\n");
se.printStackTrace ();
System.err.println (se.getMessage ());
} catch (java.io.FileNotFoundException ex) {
System.err.println("****Cannot open: " + fileName.getText() +
"\n");
} catch (java.net.MalformedURLException ex) {
// Got some other type of exception. Dump it.
ex.printStackTrace ();
} catch (java.io.IOException ex) {
// Got some other type of exception. Dump it.
ex.printStackTrace ();
}

}

class SybaseDbJimiDemoApp_btnRetrieve_actionAdapter implements
java.awt.event.ActionListener {
SybaseDbJimiDemoApp adaptee;

SybaseDbJimiDemoApp_btnRetrieve_actionAdapter(SybaseDbJimiDemoApp
adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btnRetrieve_actionPerformed(e);
}
}

class SybaseDbJimiDemoApp_btnStore_actionAdapter implements
java.awt.event.ActionListener {
SybaseDbJimiDemoApp adaptee;

SybaseDbJimiDemoApp_btnStore_actionAdapter(SybaseDbJimiDemoApp
adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btnStore_actionPerformed(e);
}
}



public static void main(String[] args) {
Frame f = new SybaseDbJimiDemoApp();
f.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.setSize(350,200);
f.setVisible(true);
}
} //end of SybaseDbJimiDemoApp.java
--
-------------------------------------------------------
ir. Werner Ramaekers werner.ramaekers@ping.be
Java Engineer http://www.ping.be/jse/
-------------------------------------------------------


Dave Clegg Posted on 1999-01-13 03:16:49.0Z
Message-ID: <369C1020.60F537C3@sybase.com>
Date: Tue, 12 Jan 1999 19:16:49 -0800
From: Dave Clegg <davec@sybase.com>
Organization: Sybase,Inc.
X-Mailer: Mozilla 4.5 [en] (WinNT; I)
X-Accept-Language: en
MIME-Version: 1.0
To: Werner Ramaekers <werner.ramaekers@ping.be>
Subject: Re: Sybase jConnect error message loading a BLOB into the database
References: <36950A1F.16FA5821@ping.be>
Content-Type: multipart/mixed; boundary="------------D94BFE7D94F2238D2445F6A2"
Newsgroups: sybase.public.jconnect40,sybase.public.jconnect30
Lines: 215
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jconnect40:229 sybase.public.jconnect30:1698
Article PK: 255138

Can you tell us the exact version of jConnect you are using and reproduce this exception
with devclasses and the JIT compiler turned off? That way I can find the line-number where

the problem is coming from.

I don't remember seeing or fixing this bug, but we test Image inserts using
setBinaryStream()
and FileInputStream all the time. Your code looks right.

Werner Ramaekers wrote:

> Hi,
>
> I'm using Sybase Adaptive Server Anywhere 6.0 and I'm trying to load an
> image into the database using Sybase's jConnect jdbc driver.
> I've succesfully created the following table in the database :
> <quote>
> createString = "create table IMAGES " +
> "(ID int, " +
> "IM image) ";
> </quote>
>
> However if I want to insert an image into the database using the source
> attached below i get the following error :
> C:\ddisk\Java\Projects\Jimi\Demo>java SybaseDbJimiDemoApp
> Reading File: dilbert.gif from local filesystem
>
> ****Now inserting a blob****
>
> Executing insert #images values(1, ?)
>
> Exception occurred during event dispatching:
> java.lang.ClassCastException: java.io.FileInputStream
> at
> com.sybase.tds.TdsDataOutputStream.dataTypeInfo(TdsDataOutputStream.j
> ava)
> at com.sybase.tds.DataFormat.<init>(DataFormat.java)
> at com.sybase.tds.TdsParam.makeFormat(TdsParam.java)
> at com.sybase.jdbc.ParamManager.makeFormats(Compiled Code)
> at com.sybase.tds.ParamFormatToken.<init>(ParamFormatToken.java)
> at com.sybase.tds.Tds.sendParamStream(Tds.java)
> at com.sybase.tds.Tds.language(Tds.java)
> at com.sybase.jdbc.SybStatement.sendQuery(SybStatement.java)
> at com.sybase.jdbc.SybStatement.execute(SybStatement.java)
> at
> com.sybase.jdbc.SybPreparedStatement.execute(SybPreparedStatement.jav
> a)
> at
> SybaseDbJimiDemoApp.btnStore_actionPerformed(SybaseDbJimiDemoApp.java
> :126)
> at
> SybaseDbJimiDemoApp$SybaseDbJimiDemoApp_btnStore_actionAdapter.action
> Performed(SybaseDbJimiDemoApp.java:166)
> at java.awt.Button.processActionEvent(Button.java:256)
> at java.awt.Button.processEvent(Button.java:229)
> at java.awt.Component.dispatchEventImpl(Compiled Code)
> at java.awt.Component.dispatchEvent(Compiled Code)
> at java.awt.EventDispatchThread.run(Compiled Code)
>
> This is the source code of SybaseDbJimiDemoApp:
> import java.awt.*;
> import java.awt.event.*;
> import java.sql.*;
> import java.util.*;
> import com.sybase.utils.Debug;
>
> public class SybaseDbJimiDemoApp extends Frame {
>
> Label lblMain = new Label("Status :");
> TextField fileName = new TextField("dilbert.gif");
> Label fileLabel = new Label("FileName");
> Button retrieveButton = new Button("Retrieve from db");
> Button storeButton = new Button("Store in db");
> String insertQuery = "insert #images values(1, ?)";
> String selectQuery = "select img from #images where id=1";
>
>
> public SybaseDbJimiDemoApp() {
> setTitle("Db JIMI Demo App");
>
> Panel p = new Panel();
> p.setLayout(new FlowLayout());
> retrieveButton.addActionListener(new
> SybaseDbJimiDemoApp_btnRetrieve_actionAdapter(this));
> p.add(retrieveButton);
> storeButton.addActionListener(new
> SybaseDbJimiDemoApp_btnStore_actionAdapter(this));
> p.add(storeButton);
>
> Panel p1 = new Panel();
> p1.setLayout(new FlowLayout());
> p1.add(lblMain);
>
> Panel p2 = new Panel();
> p2.setLayout(new BorderLayout());
> p2.add(p, BorderLayout.NORTH);
> p2.add(p1, BorderLayout.SOUTH);
>
> add(p2, BorderLayout.SOUTH);
>
> fileName.setEditable(false);
> p = new Panel();
> p.setLayout(new FlowLayout());
> p.add(fileLabel);
> p.add(fileName);
> add(p, BorderLayout.NORTH);
>
> try {
> DriverManager.registerDriver (new com.sybase.jdbc.SybDriver());
> } catch(Exception e) {
> System.err.println(e.getMessage());
> }
>
> }
>
> void btnRetrieve_actionPerformed(ActionEvent e) {
> // btnRetrieve event Handler.
> //
> // ** This is where the code that retrieves an image from the
> database
> // ** and puts it in a local file
> //
> // (Later !)
> //
>
>
> }
>
> void btnStore_actionPerformed(ActionEvent e) {
> // btnStore event Handler.
> //
> // ** This is where the code that reads a local file into
> // ** the Database goes: (This is where the important code is)
> //
> try {
> Connection conn = DriverManager.getConnection
> ("jdbc:sybase:Tds:10.125.16.113:2638", "dba", "sql");
>
> java.io.File fd = new java.io.File(fileName.getText());
> java.io.InputStream instream = new java.io.FileInputStream(fd);
> System.out.println ("Reading File: " +fileName.getText()
> + " from local filesystem \n");
>
> Statement stmt= conn.createStatement();
> stmt.executeUpdate("set textsize 100000");
>
> PreparedStatement pstmt =
> conn.prepareStatement(insertQuery );
>
> System.out.println("\n****Now inserting a blob****\n");
> System.out.println("Executing " + insertQuery + "\n" );
>
> pstmt.setBinaryStream(1, instream, (int)instream.available());
> pstmt.execute();
> pstmt.close();
>
>
> } catch (java.sql.SQLException se) {
> System.err.println ("Caught SQL Exception\n\n");
> se.printStackTrace ();
> System.err.println (se.getMessage ());
> } catch (java.io.FileNotFoundException ex) {
> System.err.println("****Cannot open: " + fileName.getText() +
> "\n");
> } catch (java.net.MalformedURLException ex) {
> // Got some other type of exception. Dump it.
> ex.printStackTrace ();
> } catch (java.io.IOException ex) {
> // Got some other type of exception. Dump it.
> ex.printStackTrace ();
> }
>
> }
>
> class SybaseDbJimiDemoApp_btnRetrieve_actionAdapter implements
> java.awt.event.ActionListener {
> SybaseDbJimiDemoApp adaptee;
>
> SybaseDbJimiDemoApp_btnRetrieve_actionAdapter(SybaseDbJimiDemoApp
> adaptee) {
> this.adaptee = adaptee;
> }
>
> public void actionPerformed(ActionEvent e) {
> adaptee.btnRetrieve_actionPerformed(e);
> }
> }
>
> class SybaseDbJimiDemoApp_btnStore_actionAdapter implements
> java.awt.event.ActionListener {
> SybaseDbJimiDemoApp adaptee;
>
> SybaseDbJimiDemoApp_btnStore_actionAdapter(SybaseDbJimiDemoApp
> adaptee) {
> this.adaptee = adaptee;
> }
>
> public void actionPerformed(ActionEvent e) {
> adaptee.btnStore_actionPerformed(e);
> }
> }
>
>
>
> public static void main(String[] args) {
> Frame f = new SybaseDbJimiDemoApp();
> f.addWindowListener(
> new WindowAdapter() {
> public void windowClosing(WindowEvent e) {
> System.exit(0);
> }
> });
> f.setSize(350,200);
> f.setVisible(true);
> }
> } //end of SybaseDbJimiDemoApp.java
> --
> -------------------------------------------------------
> ir. Werner Ramaekers werner.ramaekers@ping.be
> Java Engineer http://www.ping.be/jse/
> -------------------------------------------------------


Download VCard davec.vcf


Stephan Eckner Posted on 1999-01-25 22:15:11.0Z
Reply-To: "Stephan Eckner" <info@sq-lab.de>
From: "Stephan Eckner" <ecki@sq-lab.de>
References: <36950A1F.16FA5821@ping.be> <369C1020.60F537C3@sybase.com>
Subject: Re: Sybase jConnect error message loading a BLOB into the database
Date: Mon, 25 Jan 1999 23:15:11 +0100
Lines: 12
Organization: SQ-Lab Software GmbH
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Message-ID: <GuSEn$KS#GA.207@forums.powersoft.com>
Newsgroups: sybase.public.jconnect40,sybase.public.jconnect30
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jconnect40:228 sybase.public.jconnect30:1697
Article PK: 256518

We have got a database doing the same, in our configuration its works. If
its still interesting, mail me at: mailto:ecki@sq-lab.de

I will then post the code.

By the way, inserting Blobs into a database under ASA 6.0 is not the point.
Getting them back is another things. There is a bug in ASA 6.0, install ASA
6.01 to retrieve the Blobs.


Stephan Eckner Posted on 1999-02-23 13:01:48.0Z
From: "Stephan Eckner" <se@sq-lab.de>
Subject: Re: Sybase jConnect error message loading a BLOB into the database
References: <36950A1F.16FA5821@ping.be> <369C1020.60F537C3@sybase.com> <GuSEn$KS#GA.207@forums.powersoft.com>
Message-ID: <01be5f2d$495c37e0$5f229c3e@Noname>
X-Newsreader: Microsoft Internet News 4.70.1155
Newsgroups: sybase.public.jconnect40,sybase.public.jconnect30
Date: Tue, 23 Feb 1999 08:01:48 -0500
Lines: 10
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jconnect40:227 sybase.public.jconnect30:1696
Article PK: 256517

Hm, forget the thing about ASA 6.01. It doesn't work either.
To set and get Images from a database works here only with 5.504 and OSG.
Greetings Ecki
Stephan Eckner

> By the way, inserting Blobs into a database under ASA 6.0 is not the
point.
> Getting them back is another things. There is a bug in ASA 6.0, install
ASA
> 6.01 to retrieve the Blobs.