1 Replies - 6362 Views - Last Post: 09 December 2007 - 05:37 AM Rate Topic: -----

#1 anjali_gargcs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 19-October 07

HOW TO UPLOAD .DOC FILE USING SQL Server 2000

Posted 08 December 2007 - 11:29 PM

I have done uploading of .doc file on the server using this code its working if I want to do same thing using SQL server 2000 then how to do it?i want to say that if i want to upload a file in database then what i have to do.then how to read that file using jsp code.
its like a web site develoment using jsp
if anyone wants to see any resume then how he can see that? plz tell me.
<!-- upload.jsp -->
<%@ page import="java.io.*" %>

<%
String contentType = request.getContentType();
System.out.println("Content type is :: " +contentType);
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();

byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}

String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
//out.print("FileName:" + saveFile.toString());

//out.print(dataBytes);

int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
//out.println(boundary);
int pos;
pos = file.indexOf("filename=\"");

pos = file.indexOf("\n", pos) + 1;

pos = file.indexOf("\n", pos) + 1;

pos = file.indexOf("\n", pos) + 1;


int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
saveFile = "C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\\ROOT\\Extrusions\\" + saveFile;
FileOutputStream fileOut = new FileOutputStream(saveFile);


//fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();

out.println("File saved as " +saveFile);

}
%>

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: HOW TO UPLOAD .DOC FILE USING SQL Server 2000

#2 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: HOW TO UPLOAD .DOC FILE USING SQL Server 2000

Posted 09 December 2007 - 05:37 AM

You must create a connection to the SQL server and insert the file into a record. You can store the file locally and only store a reference into the database, or store the file itself into a blob or whatever datatype.
Creating the connection can be done using the J2SE way (as written in the Sun JDBC tutorial), but since you are using a webcontainer, using it to create the connections and pool them would ba good idea. Check your appserver's documentation on wtting up a connection pool. If it is done then register the connection pool as a datasource in JNDI, and from your application you could get hold of the datasource through JNDI.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1