Inserting a blob object into SQL Server thru JDBC: 2
Posted on 2000-05-08
This a a regenerated question sorry about the points i would raise it to 200 but at the moment i heve only 30
We are developing an email system
we r using JavaMail API for sending a mail thru SMTP client
Before sending the mails we want to store it in a SQL Sever table.
we r using javax.mail.internet.MimeMessage object
to store the message we want to stote this MimeMessage object into the database into a coloumn for msg body
We r using PreparedStatement for this
for inserting the message body into the table, but did'nt succeed.
This is our code
pstmt = conSQLServer.prepareStatement("Insert into abc values(1, ?)");
instream = mimeMsg.getInputStream();
i = pstmt.execute();
Just tell us wheather this is a right approch or not ???
and any other method we can use for this
Thanks in advance
Using stream is the right way.
I have several questions:
- what does "didn't succeed" mean? Exception thrown, result not there...
- what JDBC driver are you using?
- SQL server is this the MS SQL server?
Some ideas to continue:
1. Comment the MimeObject stuff and try to write as a stream a byte array for example, using ByteArrayInputStream.
2. If 1 works, the problem is with the handling of the MimeObject serialization.
3. If it does not work, the problem is in your statement or server(?), since I have done stream updates and they normally work.
4. try changing the execute() to executeUpdate()
1.Does your message body conatin any attachments.
2. Are you taking the message body (only text)from any GUI
if you are taking only text you can convert that into string and store that one into varchar2 or some thing like that.
tell me if there are any attachments in the message body.
What type of input stream you are using ? If you are using FileInputStream try putting this lines in your code :-
File f = new File();
PrepareStatement dbstmt = con.preparestatement();
InputStream is = new FileInputStream(f);
dbstmt.setBinaryStream(int i, is, (int)f.length());
Have you tried using the setBytes method using a byte array constructed with the data to be set??
I have only used the Blob once didn't quite go much into it though.
But I hope it helps