Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


farah
insert data
0 Answer(s)      3 years and 11 months ago
Posted in : Java Beginners


i've got a problem to insert my data to database.i can upload my multipart file but not text data.Please help me to solve this .Attached herewith my source code..

a)index.jsp

<%@ page import="java.util.Date,java.text.DateFormat,java.text.SimpleDateFormat"%>
<%
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();

%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Page Insert</title>
</head>

<body>
<form action="formpost.jsp" method="post" ENCTYPE="multipart/form-data" >
<table width="361" border="2" align="center">

<tr>
<th scope="row">TRANSACTION</th>

<td><input type="text" name="transaction" readonly="true" value="<%=dateFormat.format(date)%>">
</tr>
<tr>
<th scope="row">VALID START </th>
<td><select name="start" size="1" >
<option>equal</option>
<option>before</option>
<option>after</option>
<option>meet</option>
<option>met_by</option>
</select>
<input type="text" name="textfield" size="15">
</tr>
<tr>
<th scope="row">VALID END </th>
<td><select name="end" size="1" id="end">
<option>equal</option>
<option>before</option>
<option>after</option>
<option>meet</option>
<option>met_by</option>
</select>
<input type="text" name="textfieldd" size="15">
</tr>
<tr>
<th> UPLOAD FILE </th>
<td><input type="file" name="file"></td>
</tr>
</table>


<p align="center">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</p>

</form>
</body>
</html>

b)formpost.jsp


<%@page import="java.text.*,java.io.*,java.sql.*" %>
<% //obtain parameter from the client
String transaction=request.getParameter("transaction");
String start=request.getParameter("start");
String textfield=request.getParameter("textfield");
String end=request.getParameter("end");
String textfieldd=request.getParameter("textfieldd");

try{

Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root", "daisy");
PreparedStatement st =
con.prepareStatement("insert into images values(?,?,?,?,?)");

st.setString(2, transaction);
st.setString(3, start);
st.setString(4, textfield);
st.setString(5, end);
st.setString(6, textfieldd);
st.executeUpdate();
} catch (Exception e) {
System.out.println(e.getMessage());
}


%>

<% //to get the content type information from JSP Request Header
String contentType = request.getContentType();
//here we are checking the content type is not equal to Null and as well as the passed data from mulitpart/form-data is greater than or equal to 0
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,contentType.length());
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
String folder = "C:/Program Files/Apache Software Foundation/Apache Tomcat 6.0.20/webapps/ROOT/upload/web/";
FileOutputStream fileOut = new FileOutputStream(folder+saveFile);
//out.print("Saved here: " + saveFile);
//fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
}
%>

c)table created as below:-

(
id INT not null primary key,
transaction VARCHAR(15),
startoperator VARCHAR(15),
startvalid VARCHAR(15),
endoperator VARCHAR(15),
endvalid VARCHAR(15)
)

Advertisement
View Answers

Related Tutorials/Questions & Answers:
insert data
insert data  i've got a problem to insert my data to database.i can...("insert into images values(?,?,?,?,?)"); st.setString(2... and as well as the passed data from mulitpart/form-data is greater than or equal to 0
insert and delete data in database
insert and delete data in database  insert and delete data in database from servlets through JDBC   Hi Friend, Please visit the following links: Insert Data Delete Data Thanks
Advertisements
single query to insert the data
single query to insert the data  How to insert data for all HTML fields in single MYSQL query
insert data into database
insert data into database  hi,thanks for reply just i am doing student information project,frontend is jsp-servlet and backend is msaccess2007. i... the data into the jsp page that data stored into the database.Here the error
Insert Data From File
Insert Data From File       Insert Data From File is  used to insert data from file... to insert data from file. To understand this example, we create a table 'Stu_Table
How to insert clob data??
How to insert clob data??  Can any one tell me in details how... to insert more than 4000 characters.I have heard that clob fields can hold 4 gb of data and need pl/sql to avail that feature.Can any one tell me how to create
database is connected but not insert the data
database is connected but not insert the data  hi, i am getting connected to database.Retrive the data also but cannot insert the data into database...=con.prepareStatement("insert into studentmaster(slno) values('"+batch+"')"); i
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
unable to insert data into database
unable to insert data into database    hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based
insert data into database
insert data into database  type Exception report message...)Go to the start->Control Panel->Administrative Tools-> data sources. 2... selecting the driver, click finish button. 4)Then give Data Source Name
EJB Insert data
.style1 { color: #FFFFFF; } EJB Insert data... describes you the way  to insert data into the database using EJB. The steps involved in inserting data are as :- 1)Create an interface named
Insert Data From File
Insert Data From File       Insert Data From File is  used to insert data from file... to insert data from file. To understand this example, we create a table 'Stu_Table
To insert maximum number of data in database.
To insert maximum number of data in database.  how to change string data type into clob data type in jsp   Hi Friend, Please visit the following link: http://www.roseindia.net/jdbc/insert-clob-example.shtml Thanks
FAILED TO INSERT DATA FROM FUNCTION();
FAILED TO INSERT DATA FROM FUNCTION();  HELLO, I HAVE A PROBLEM TO INSERT DATA FROM OUTPUT FROM FUNCTION()... I WANT TO STORE THE OUTPUT IN DATABASE, BUT FAILED TO INSERT... before this.... ......................... function
insert and retrive data and time - SQL
insert and retrive data and time  hello everybody . Is there any method in java so that we can insert current system time and then it can... default NULL, PRIMARY KEY (`id`) ) To insert current date and time
insert data in the database using checkbox
insert data in the database using checkbox  i am fetching data from... each row but the problem is that i am not fetching data in any textboxes so how should i insert only checked data into database on submission.   We
Insert file data into database
Insert file data into database In this section, you will learn how to insert.... Now to insert this data into the database, we have established a database connection. Then using the insert query, we have inserted whole file data
how to insert data from netbeans into databse
how to insert data from netbeans into databse  how to insert data from netbeans into databse   Please visit the following link: http://www.roseindia.net/webservices/web-services-database.shtml
Insert Mysql Blob data
Insert Mysql Blob data   In this section, we will discuss about how to insert a blob data into a database table. A Blob stores a binary large... which points to the Blob data, data is not directly stored in the row
Question about "Insert text file data into Database"
Question about "Insert text file data into Database"  Hey I was reading the tutorial "Insert text file data into Database", (awesome btw), and noticed that both a FileInputStream, a DataInputStream and a BufferedReader
Java insert file data to JTable
Java insert file data to JTable In this section, you will learn how to insert text file data into JTable. Swing has provide useful and sophisticated set...); } }  Through the above code, you can insert the file data into JTable
how to insert data into database using jsp & retrive
how to insert data into database using jsp & retrive  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
EJB Insert data
.style1 { color: #000000; } EJB Insert data... describes you the way  to insert data into the database using EJB. The steps involved in inserting data are as :- 1)Create an interface named
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi..... i ve created login page n in that a registration form also.... my doubt is-when... that data will b stored in db(m using sybase). 2.also hw to retrieve the data from
insert excel value in to oracle data base
insert excel value in to oracle data base  Hi All I am using... org.apache.poi.poifs.filesystem.POIFSFileSystem; public class Insert...(); PreparedStatement stat=con.prepareStatement("insert into login(username,password1
what is the jsp coding to insert a data in database tables
what is the jsp coding to insert a data in database tables  Dear Sir, I Want to know the coding for insert the data from jsp to oracle database.. my... departmentname and departmentid and click submit i want to save this data in my
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi, i have created... register his details,(for ex,username,password,dob,gender) 1.how that data will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u
how to insert data in database using html+jsp
how to insert data in database using html+jsp  anyone know what... = null; // declare a resultset that uses as a table for output data from... table. String QueryString = "insert into xxqc_announcement(PID,msg
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc  ? Create... and insert those inputs into database using JDBC.   Here is a jsp code... st=con.createStatement(); int i=st.executeUpdate("insert into student
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc  ? Create... and insert those inputs into database using JDBC.   Here is a jsp code... st=con.createStatement(); int i=st.executeUpdate("insert into student
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc  ? Create... and insert those inputs into database using JDBC.   Here is a jsp code... st=con.createStatement(); int i=st.executeUpdate("insert into student
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc  ? Create... and insert those inputs into database using JDBC.   Here is a jsp code... st=con.createStatement(); int i=st.executeUpdate("insert into student
insert data into mysql databse using swing
insert data into mysql databse using swing   Blockquote hi, here is my code, i want code for store data into mysql database when click on submit button from access data from this form, please provide code, import java.awt.
insert
insert  insert data in database from servlet through JDBC   Ho Friend, Please visit the following: Insert data into database Thanks
Insert XML file data to database
Insert XML file data to database In this tutorial, you will learn how to insert the xml file data to database using dom parser. You all are aware of XML file, it is a tag based language. You can easily transfer and store its data
Insert text file data into Database
Insert text file data into Database In this section, you will learn how to insert the text file data into the database. For this purpose, we have created... the data to the ArrayList. This list is then iterated through the Iterator
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Uploading Excel sheet record in JSP to insert data in MySql
Uploading Excel sheet record in JSP to insert data in MySql  Need Help how to upload Excel (.xls) file and insert data in Mysql using JSP it wil be wonder for me if any help me
i need program to insert data in database using javascript
i need program to insert data in database using javascript  please help me
take data from one table and insert same in another
take data from one table and insert same in another  I want to know when a new field update in table and the same data has to update in another table
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
using ajax i want to insert data into oracle database
using ajax i want to insert data into oracle database  i would like to insert/update/select/delete from jsp to oracle database using ajax? please send a code for this iam using oracl database thank you
how to insert data from database using oops concepts - Development process
how to insert data from database using oops concepts  Hi, How to insert data from database using oops based concepts.please write the code... the following code: import java.sql.*; class Insert{ public static String url
can i use trigger to insert data within a time period ?
can i use trigger to insert data within a time period ?  Hello sir, i want to calculate company's closing account each Saturday 12.00. In this case i... this trigger concept the data will be insert to each Employee's ID. Plz sir help me
Ant Script to Insert Data in Mysql Table
Ant Script to Insert Data in Mysql Table       This example illustrates how to insert data... INSERT INTO client (client_name) VALUES ("Galanthus nivalis"
How to insert data from textfields into database using hibernate?
How to insert data from textfields into database using hibernate?   try{ Session session = HibernateUtil.getSessionFactory().openSession...); System.out.println("Successfully data insert in database"); tx.commit
cannot insert data into ms access database - Java Server Faces Questions
cannot insert data into ms access database   go back... connection: 1. Open Data Sources (Start->Control Panel->Administrative Tool->Data Sources(ODBC) 2. Open User DSN tab 3. Add a user DSN 4. Select
getting int values from form and insert it in data base in jsp
getting int values from form and insert it in data base in jsp  how... = Integer.parseInt(s); Then you can write JDBC code to insert data...=st.executeUpdate("insert into data(name,age, address) values('"+name+"',"+age
Advertisements
 

 

 

DMCA.com