This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet  + Oracle9Ii  help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet  + Oracle9Ii  help needed" Watch "Servlet  + Oracle9Ii  help needed" New topic
Author

Servlet + Oracle9Ii help needed

reda weldu
Greenhorn

Joined: Sep 05, 2008
Posts: 1
Hi
I stored a document to my database as a blob file. that is, firest I write a document in jEditor of netbeans and using sockets i stored it in the database.
I can display(retriev) it into the jEditor again.
However, when I tried to display the document in MSWORD, it gives the following problem;
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException.
at line 8 (of the following code).

The whole code of the servlet is:

1 InputStream is=null;
2 oracle.sql.BLOB blob=null;
3 HttpServletRequest req=null;
4 HttpServletResponse res=null;
5 String fileselected=(String) jList1.getSelectedValue();

6 OutputStream os;
7 try {
8 res.setContentType("application/msword"); // error here
9 os = res.getOutputStream();
10 try{
11 Statement st = con1.createStatement();
12 ResultSet rs = st.executeQuery("SELECT EDITED_FILE FROM DARAS.TBLEDIT WHERE EDITIONNAME="+fileselected);
while (rs.next()){
blob=((OracleResultSet)rs).getBLOB(2);
is=blob.getBinaryStream();
}
int pos=0;
int length=0;
byte[] b = new byte[blob.getChunkSize()];
while((length=is.read(b))!= -1){
pos+=length;
os.write(b);

}
is.close();
}//try
catch (SQLException se)
{
se.printStackTrace();
}
} catch (java.io.IOException ex) {
ex.printStackTrace();
}
Could you correct it please?
I am also not sure what plug_ins to add.
with great regards
[ September 06, 2008: Message edited by: reda weldu ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
The stack trace should have included a line number for the exact statement that encountered a null pointer. That would be the place to start looking.

Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "servlet help needed" in a forum completely dedicated to questions on Servlets isn't very helpful.

Please go back and change your post to add a more meaningful subject by clicking the .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet + Oracle9Ii help needed