Question:
How to store a word file in an SQL database using Jsp codes..?.?
anonymous
1970-01-01 00:00:00 UTC
How to store a word file in an SQL database using Jsp codes..?.?
Three answers:
?
2016-10-14 09:45:19 UTC
hi ! you could try this in sq. server, with textcopy application. you should save on with properly the following steps. (do not hardship with call, you could reproduction any record not purely photo yet pdf, wav, jpg or any) [a million] Create a table on your database. operating example - create table table01 ( identity int , audio_file photo) [2] Insert a cost into it. insert into table01 values ( a million , 0x0 ) note : do not placed NULL or different element truly of 0x0. [3] style properly the following command in command. (replace Server, Database call ) (a million) Insert into database - TEXTCOPY.exe /S(community) /Uuser_name /Ppassword /D DB_NAME /T Table01 /C audio_file /F "C:tempwav001.wav" /W"the position identity=a million" /I (2) Out to a record from database - TEXTCOPY.exe /S(community) /Uuser_name /Ppassword /D DB_NAME /T Table01 /C audio_file /F "C:tempwav002.wav" /W"the position identity=a million" /O ===============
Siju
2012-11-26 03:31:50 UTC
<%@page language="java" session="true"

import="java.io.*,java.util.*,java.io.*,java.sql.*,javax.servlet.*"%>

<%

//to get the content type information from JSP Request Header

String contentType = request.getContentType();



if (contentType != null && contentType.indexOf("multipart/form-data") >= 0)

{

DataInputStream in = new DataInputStream(request.getInputStream());

//we are taking the length of Content type data

int formDataLength = request.getContentLength();

byte dataBytes[] = new byte[formDataLength];

int byteRead = 0;

int totalBytesRead = 0;

//this loop converting the uploaded file into byte code

while (totalBytesRead < formDataLength)

{

byteRead = in.read(dataBytes, totalBytesRead, formDataLength);

totalBytesRead += byteRead;

}

String file = new String(dataBytes);

//for saving the file name

String saveFile = file.substring(file.indexOf("filename="") + 10);

saveFile = saveFile.substring(0, saveFile.indexOf("\n"));

saveFile = saveFile.substring(saveFile.lastIndexOf("") + 1,saveFile.indexOf("""));

int lastIndex = contentType.lastIndexOf("=");

String boundary = contentType.substring(lastIndex + 1);

int pos;

//extracting the index of file

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;

// creating a new file with the same name and writing the content in new file

//FileOutputStream fileOut = new FileOutputStream(saveFile);

FileOutputStream fileOut = new FileOutputStream("C:\\Program Files\\Apache Software Foundation\\Tomcat 5.0\\webapps\\incidentreportform_main\\upload"+saveFile+"");

fileOut.write(dataBytes, startPos, (endPos - startPos));

fileOut.flush();

fileOut.close();





//out.println(saveFile);



Connection con=null,con1=null;

Statement stmt=null,stmt1=null;

PreparedStatement ps=null,ps1=null;

ResultSet rs=null,rs1=null;

String sql="",sql1="",a="";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:inficert","inficert","inficert");

stmt=con.createStatement();

String sno=request.getParameter("parameter");

int j1=0;



try

{

sql="UPDATE department set crftitle =('"+saveFile+"') where sno='"+sno+"'";

j1=stmt.executeUpdate(sql);

if(j1!=0)

{

%>







<%



}



}

catch(Exception ex)

{

ex.printStackTrace();

}



}

%>
Sammy
2012-11-27 03:00:10 UTC
Well if you are using Jsp to store data then you would definetely aboutXML file. JSP store data entered by user into XML file. Okie let me explain you fully the steps how to store word file in SQl database -



1)form.jsp:



















Name:
Address:
Contact No:
Email:








2)createxml.jsp:



<%@page import="java.io.*,org.w3c.dom.*,javax.xml.parsers.*,javax.xml.transform.*, javax.xml.transform.dom.*,javax.xml.transform.stream.*"%>



<%!

public void createXmlTree(Document doc,String name,String address,String contact,String email) throws Exception {

System.out.println(name);

Element root = doc.createElement("Employee");

doc.appendChild(root);



Element child1 = doc.createElement("Name");

root.appendChild(child1);



Text text1 = doc.createTextNode(name);

child1.appendChild(text1);



Element child2 = doc.createElement("Address");

root.appendChild(child2);



Text text2 = doc.createTextNode(address);

child2.appendChild(text2);



Element child3 = doc.createElement("ContactNo");

root.appendChild(child3);



Text text3 = doc.createTextNode(contact);

child3.appendChild(text3);



Element child4 = doc.createElement("Email");

root.appendChild(child4);



Text text4 = doc.createTextNode(email);

child4.appendChild(text4);



TransformerFactory factory = TransformerFactory.newInstance();

Transformer transformer = factory.newTransformer();



transformer.setOutputProperty(OutputKeys.INDENT, "yes");



StringWriter sw = new StringWriter();

StreamResult result = new StreamResult(sw);

DOMSource source = new DOMSource(doc);

transformer.transform(source, result);

String xmlString = sw.toString();



File file = new File("c:/emp.xml");

BufferedWriter bw = new BufferedWriter(new FileWriter(file));

bw.write(xmlString);

bw.flush();

bw.close();



}%>

<%

String name=request.getParameter("name");

String address=request.getParameter("address");

String contact=request.getParameter("contact");

String email=request.getParameter("email");

try{

System.out.println(name);

DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();

Document doc = docBuilder.newDocument();

createXmlTree(doc,name,address,contact,email);



out.println("Xml File Created Successfully");

}

catch(Exception e)

{

System.out.println(e);

}

%





I think your question has been resolved till yet if you still have problem then i will definetly explain it in another way.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...