|
|
Re: How to retrieve an Oracle BLOB from Java [message #99818 is a reply to message #99676] |
Thu, 11 April 2002 13:31 |
German
Messages: 1 Registered: April 2002
|
Junior Member |
|
|
I canīt retreive an Oracle Blob from JAVA.
The problem is, when I do...executeQuery("select * from table"); oracle returns a General Error.
I canīt retrieve a Blob. But I had no problem with other things like varchar2 or numbers.
All the examples in the net are the same,... with the same problem. How can I fix it ?
|
|
|
|
|
|
|
Re: How to insert/retrieve a BLOB from VB [message #101058 is a reply to message #99714] |
Fri, 09 April 2004 01:42 |
Tariq Khan
Messages: 2 Registered: April 2004
|
Junior Member |
|
|
Private Sub cmdSaveBLOBToFile_Click()
' ******************************************************************
' *** This event will take a BLOB that has already been inserted ***
' *** into the database and save it as a file. ***
' ******************************************************************
On Error GoTo ErrorHandler
Screen.MousePointer = vbHourglass
Set cn = New ADODB.Connection
If ConnectivityMethod = "ODBC" Then
' ODBC Connection Setup
Set cn = New ADODB.Connection
With cn
.ConnectionString = ODBCConnectString
.Open
End With
Else
' OLEDB Provider Connection Setup
cn.Provider = "OraOLEDB.Oracle"
cn.ConnectionString = OLEDBConnectString
cn.Open
End If
Set rs = New ADODB.Recordset
' 'blobtest.txt' is the name of a BINARY file that has been stored in the
LOB_TABLE in the database
rs.Open "Select * from LOB_TABLE where FIELD = '" & BlobFileName & "'",
cn, adOpenKeyset, adLockOptimistic
' Create ADO stream object
Set mStream = New ADODB.Stream
' Set it to a binary file type
mStream.Type = adTypeBinary
' Open it
mStream.Open
' This writes the image from the blob field to the buffer
mStream.Write rs.Fields("BLOBFIELD").Value
' This saves the stream to a file on disk
mStream.SaveToFile BlobDestPath & rs.Fields("FIELD").Value
mStream.Close
Set mStream = Nothing
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Screen.MousePointer = vbDefault
MsgBox "Blob saved to file as " & BlobDestPath & BlobFileName, , "Blob
Saved"
Exit Sub
ErrorHandler:
Screen.MousePointer = vbDefault
Select Case Err.Number
Case 3004
MsgBox "Could not write file.", , "File Already Exists"
Case Else
MsgBox Err.Number & " - " & Err.Description, , "Error Msg"
End Select
End Sub
- - - - - - - - - - - - - - - - Code ends
here - - - - - - - - - - - - - - - -
Sample Output
-------------
Message boxes confirming the upload and retrieval of the LOBs will be
displayed and any LOB's retrieved from the Oracle database will be stored
into the 'C:Temp' folder on your computer.
|
|
|
Re: How to insert/retrieve a BLOB from VB [message #101059 is a reply to message #101058] |
Fri, 09 April 2004 01:45 |
Tariq Khan
Messages: 2 Registered: April 2004
|
Junior Member |
|
|
Private Sub cmdSaveBLOBToDB_Click()
' *******************************************************************
' *** This event will insert a BLOB from a file into the database ***
' *******************************************************************
On Error GoTo ErrorHandler
Screen.MousePointer = vbHourglass
Set cn = New ADODB.Connection
If ConnectivityMethod = "ODBC" Then
' ODBC Connection Setup
Set cn = New ADODB.Connection
With cn
.ConnectionString = ODBCConnectString
.Open
End With
Else
' OLEDB Provider Connection Setup
cn.Provider = "OraOLEDB.Oracle"
cn.ConnectionString = OLEDBConnectString
cn.Open
End If
Set rs = New ADODB.Recordset
rs.Open "Select * from LOB_TABLE", cn, adOpenKeyset, adLockOptimistic
' Create the ADO Stream object
Set mStream = New ADODB.Stream
' Make it a binary type
mStream.Type = adTypeBinary
' Open the stream
mStream.Open
' Read the binary file into the stream buffer
mStream.LoadFromFile BlobSourcePath & BlobFileName
' Add the blob to the database
With rs
.AddNew
.Fields("BLOBFIELD").Value = mStream.Read
.Fields("FIELD").Value = BlobFileName
.Update
End With
mStream.Close
Set mStream = Nothing
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Screen.MousePointer = vbDefault
MsgBox "Blob inserted into DB from " & BlobSourcePath & BlobFileName, ,
"Blob Inserted"
Exit Sub
ErrorHandler:
Screen.MousePointer = vbDefault
Select Case Err.Number
Case 3002
MsgBox "Could not read file, check the path.", , "File Not Found"
Case Else
MsgBox Err.Number & " - " & Err.Description, , "Error Msg"
End Select
End Sub
|
|
|
Re: How to retrieve an Oracle BLOB from Java [message #198535 is a reply to message #99818] |
Tue, 17 October 2006 09:20 |
nix5402
Messages: 1 Registered: October 2006 Location: New Hampshire
|
Junior Member |
|
|
In response to the problem:
-----
"when I do...executeQuery("select * from table"); oracle returns a General Error."
------
Answer:
I suggest that you contact Oracle to verify
that you are using the correct string for connecting to the
database. I was getting a similar error because unknown to
me my connection string was specifying a non-oracle driver.
The connection method that worked for me is:
Class.forName( "oracle.jdbc.OracleDriver");
Connection my_conn = DriverManager.GetConnection (
"jdbc:oracle:thin:@bmds14:1521:bmds",
userName, Password);
where
"bmdsrv14" is the name of my Oracle server,
"1521" is the port number on the Oracle server, and
"bmds" is my sid.
Please let me know if this solves your problem.
|
|
|