Hi, All:
I met a problem when I tried to use the
ObjectInputStream to read the binary data that I
retrieved from the SQL Server. Here is the code:
import java.io.*;
import java.sql.*;
import java.util.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ResultServlet extends
HttpServlet
{
public void doGet(HttpServletRequest
req, HttpServletResponse res) throws ServletException,
IOException
{
String number =
req.getParameter("idnum");
System.out.println("number="+number);
try {
// Register JDBC/ODBC Driver in jdbc
DriverManager
// On some platforms with some java
VMs, newInstance() is
//necessary...
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
// Test with MS Access database
(rjdemo ODBC data source)
String url = "jdbc:odbc:mysqldb";
Connection c =
DriverManager.getConnection(url,
"Joezhou", "password");
PreparedStatement stmt
=c.prepareStatement("select graphics
from anno where num=?");
stmt.setString(1, number);
ResultSet rs=stmt.executeQuery();
rs.next();
InputStream in =
rs.getBinaryStream("graphics");
ObjectInputStream objin =new
ObjectInputStream(in);
Object obj=objin.readObject();
Vector v = new Vector();
v=(Vector)obj;
rs.close();
for(int i = 0; i < v.size(); i++)
{
System.out.println(v.elementAt(i));
}
ObjectOutputStream out = new
ObjectOutputStream(res.getOutputStream());
out.writeObject(v);
}catch(Exception e)
{
e.printStackTrace();
}
}
}
I got an EOFException when this servlet is called by
the applet that I wrote. And by using multiple
"System.out.println"s, I have figured out that the
problem is at the line
"ObjectInputStream objin =new ObjectInputStream(in);"
I don't know how to solve this problem. But I did run
the standalone java application successfully before
that has the exactly same code as this one except that
that program is a normal java program(not servlet) and
all it does is gets the vector from the database and
prints every element out to the
console.
Your advice is greatly appreciated.
Sincerely,
-Joe
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html