String Exception Program

String Exception Program

View Answers

September 9, 2008 at 6:14 PM

Hi friend,

<%@ page language="java" %>
<HTml>
<HEAD>
<TITLE>Display file upload form to the user</TITLE></HEAD>

<BODY>
<A HREF = "loginForm.jsp"><b>Home</b></A>
<center>
<br><br><br>
<table border="1" bgcolor="bluelight" cellspacing="0" cellpadding="0">
<tr>
<td>
<FORM ENCTYPE="multipart/form-data" ACTION="FileUploadAction.jsp" METHOD=POST>
<center><colspan="2" align="center"><B>File upload into Database</B><center>

<center>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
<tr>
<td colspan="2" align="center">&nbsp;</td>
</tr>
<tr>
<td><b>Select file To Upload:</b></td>
<td><INPUT NAME="file" TYPE="file" size="50"></td>
</tr>
<tr>
<td colspan="2" align="center">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><INPUT TYPE="submit" VALUE="Send File" ></td>
</tr>
<table>
</center>
</FORM>
</td>
</tr>
</table>
</center>
</body>
</html>


September 9, 2008 at 6:16 PM

<%@ page import="java.io.*,java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<html>
<%
int val =0;
String contentType = request.getContentType();
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);
System.out.println("saveFile=" + saveFile);
saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+ 1,saveFile.indexOf("\""));
System.out.println("saveFile" + saveFile);
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;

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;

FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
%>

<%
Connection con=null;
PreparedStatement pstatement = null;
String line = null;
String value=null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String dbName = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName = "amar";
String password = "amar123";
try{
StringBuilder contents = new StringBuilder();
BufferedReader input = new BufferedReader(new FileReader(saveFile));
while (( line = input.readLine()) != null){
contents.append(line);
}
value = contents.toString();
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url+dbName,userName,password);
java.util.Date now = new java.util.Date();
String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
String strDateNew = sdf.format(now) ;
String queryString = "INSERT INTO FileUpload set filename='"+value+"',filedate='"+strDateNew+"'";

pstatement=con.prepareStatement(queryString);
val = pstatement.executeUpdate();

if(val>0){
%>
<br><br>
<b>File <% out.println(saveFile); %> has been uploaded and inserted into Database at <%=strDateNew%>.</b>
<%
}

}
catch(Exception e)
{}
}
%>
</html>
---------------------------------------------------

Thanks & Regards

Amardeep









Related Tutorials/Questions & Answers:
String Exception Program - JSP-Servlet
String Exception Program  Respected Sir/Madam, I am... the JasperException StringIndexOutOfBound Exception- 54164.. I am sending the code for your kind reference: <% int val =0; String contentType
Out of bounce exception in the string reverse program - Java Beginners
Out of bounce exception in the string reverse program  In the given program below this is taken from ur site but when i am executing it.It is giving an exception like string out of bounce.So please give me the correct solution
Advertisements
string program
string program  write a program to print the pattern p r o program r a m
string program
string program  wap to find single occurrence of given string in java without using any predefined method
string program
string program  reads sentence and find the average length of word... AverageLengthOfWords { public static void main(String[] args...); System.out.print("Enter sentence: "); String st=input.nextLine(); String str
String program - Java Beginners
String program  write a program to accept a word. Pass it to the function magic(String x). The function checks the string for the presence... prints it is a magic string otherwise it prints not a magic string.  
String reverse program
String reverse program  write a java program for reverse string? if the string is "Hi welcome to hyderabad" the reverse string is "hyderabad... for help. You can split the String into String array using split method of String
Exception Handling-Error Messages in Program
Exception Handling-Error Messages in Program  Sorry about the first code block: import java.util.*; class GradeException extends Exception{ public GradeException(String s){ System.out.println(s); } } ----jGRASP exec: javac -g C
java string vowel program
java string vowel program  java string vowel program   Please visit the following links: Display the word that begins with vowel Java Count Vowels
String Function Program
String Function Program  The string function program is just an application of the string manipulation functions in JAVA. The program is designed to count the number of one-letter word, two-letter word, and three-letter words
Program to swap the string
Program to swap the string  Hi, can any one tell me the code to swap...!!   Here is an example that prompts the user to enter two string and then swaps both the string without using third variable. import java.util.*; class
Exception Handling-Error Messages in Program
java.util.*; class GradeException extends Exception{ public GradeException(String s...Exception Handling-Error Messages in Program  Hi Friend, I am having trouble running this code as per my prior question on Exception handling
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
java program for string tokenzing and parsing
java program for string tokenzing and parsing  String s="height=128 weight=22 gender=male"; i need to convert this into height="128" weight="22" gender="male" normally if we print "hello" means we use System.out.println("\"Hello
java program for string tokenzing and parsing
java program for string tokenzing and parsing  String s="height=128 weight=22 gender=male"; i need to convert this into height="128" weight="22" gender="male" normally if we print "hello" means we use System.out.println("\"Hello
A Program To Reverse Words In String in Java
A Program To Reverse Words In String in Java  A Program To Reverse Words In String in Java for example: Input:- Computer Software Output... Tell Me This Program.  Here is an example that reverse the words
Reverse String Program in Java
Reverse String Program in Java We are going to describe about reverse string program in java. In this example reverses a string entered by the user. We... Output- Here is the output of the program: Enter a String
Getting Exception on UseDefinedException sample program - Please help me how to resolve
Getting Exception on UseDefinedException sample program - Please help me how to resolve  class UseDefinedException extends Exception{ String msg...(String args[]) throws Exception { for(int i=1;i<=5;i
Unhandled Exception
; that are thrown  during the execution of program. These exception are never caught during the execution of program. This result in nasty Exception stack. Usually this type... to catch each and every exception in the program. There are some unavoidable exception
Program using String functions - Java Beginners
Program using String functions  Write a program to accept a sentence... { public static void main(String[] args) { int count = 0...); System.out.print("Enter string:"); String st = input.nextLine
exception
exception  example for numberformat exception   Hi Friend...{ public static void main(String[] args) { try{ String st="Rose...); } catch(Exception e){ System.out.println(e
exception
{ public static void main(String[] args)throws Exception { for (String s... arguments are not equalto two,throw a user defined exception "invalid parameter exception" ,otherwise display the two parameters.   Here is an example
Exception
main(String args[])throws Exception { FooException oo=new FooException...Exception  public class FooException extends Exception { public..."); } public FooException(String message) { super(message
Exception
Exception  whis is the Arithmetic Exception in java? or define Arithmetic Exception with exp?   Arithmetic Exception occurs, when you...(String args[]) { int d, a; try { d = 0; a = 42 / d; System.out.println
exception
exception   Create a program that takes user name as input from user... defined checked exception ââ?¬Å?InvalidCharcterFoundExceptionââ?¬Â? and creater a block of codes that will handle the exception
exception
exception  wHEN RUNTIME EXCEPTION CLASS IS SUB OF EXCEPTION CLASS HOW CAN'T HANDLE UNCHECKED EXCEPTION
exception
exception  Identify the reason for SQLException exception, which... a row in the Status table: String str = "INSERT INTO Status VALUES...(String[] args){ try{ Class.forName("com.mysql.jdbc.Driver
Exception handling in java
in java. Java program many provides exception. We are handle of error in program when during execution in a program .we are generate of exception try() block... class in the program Instantiation Exception Instantiation Exception
exception
exception  chek in and check out exception in java   Please visit the following link: Checked and Unchecked Exception
string
string  a java program to input a string and display the string... main(String[]args) throws Exception{ System.out.print("Enter the sentence...*; import java.io.*; public class FirstLetter{ public static String
exception
exception  what is the use of catch block even though we have predefined exception object
Exception
package.ADS_TO_REPLACE_1 The NullPointerException is thrown by the Java program... of NullPointerException in Java program: * If you are calling some method on the null... code if you try to call the length method the Java program will though
Exception
Exception   I was creating a table dynamically but it shows exception i.e shown down Suplier created0 Suplier created0 Suplier created0 Product created0 Product created0 Product created0 Product created0 could not fetch initial
exception
user defined unchecked exception  can we create user defined unchecked exceptions? if so what is the exact use of it in real time?   Please visit the following links: http://www.roseindia.net/java/java-exception/user
EXCEPTION
implements interface1,interface2{ public static void main(String []args
Exception handling mechanism
handling mechanism in java. Exception means error in your program. Exception handling mechanism is a way to handle the exception in your program. Using three... handling mechanism public class Exception { public static void main(String
String
(String args[]) throws Exception { System.out.println(addSpaceToRight("Hello", 10...String  how to add spaces with string functions.?   Hi... { public static String addSpaceToRight(String s, int n) { return String.format
I am writing a program which converts a string to a timestamp and add days to it
I am writing a program which converts a string to a timestamp and add days to it  java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2012-01-11 12:34:39"); long l=ts2.getTime() +(100060602424);//add 24 days Date d=new Date(l
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
Java String Occurrence in a String
Java String Occurrence in a String       In this program you will learn how to find the occurrence of a String in another String. Here we have already taken a String
string
string  write a program to accept the string and store the reverse stream into another array and print
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
string
string   just i want to a program in a short form to the given string in buffered reader for example input string: Suresh Chandra Gupta output: S. C...; public class StringTest { public static void main(String [] args
Constructor Exception in Java
as a parameters. The main reason of exception occurring in the program is ...;} } output of the program Exception in thread... Constructor Exception in Java   
Exception Classes
Exception Classes       The hierarchy of exception classes commence from Throwable class which is the base class for an entire family of exception classes, declared in 
java exception
java exception   define an exception called no match exception tat z thrown wen a string z not equal to india   class ExceptionExample { public static void main(String[] args) throws Exception { String

Ads