The datafile which we need to upload to tables in our project, is an external ".CSV" file which has text in the following format (This is just 1/20 th part of it..the remaining has more sets as these, nearly 20 sets of such data with different values)
@110516060031<M02m00-7959=+35.69,+35.69,+35.68,+35.68,+35.69,+35.69,+35.71,+35.71,+35.71,+35.71,+35.69,+35.69,+35.68,+35.68,+35.69,+35.69,+35.72,+35.72,+35.76,+35.76,+35.80,+35.80,+35.83,+35.83,+35.86,+35.86,+35.86,+35.86,+35.86,+35.86,+35.87,+35.87,+35.87,+35.87,+35.83,+35.83,+35.80,+35.80,+35.76,+35.76,+35.75,+35.75,+35.76,+35.76,+35.75,+35.75,+35.73,+35.73,+35.73,+35.73,+35.76,+35.76,+35.75,+35.75,+35.73,+35.73,+35.69,+35.69,+35.68,+35.68,+35.66,+35.66,+35.66,+35.66,+35.62,+35.62,+35.61,+35.61,+35.58,+35.58,+35.54,+35.54,+35.53,+35.53,+35.51,+35.51,+35.51,+35.51,+35.51,+35.51,+35.51,+35.51,+35.51,+35.51,+35.51,+35.51,+35.53,+35.53,+35.53,+35.53,+35.53,+35.53,+35.51,+35.51,+35.51,+35.51,+35.51,+35.51,+35.54,+35.54,+35.53,+35.53,+35.55,+35.55,+35.59,+35.59,+35.59,+35.59,+35.59,+35.59,+35.62,+35.62,+35.64,+35.64,+35.64,+35.64,+35.66,+35.66,+35.66,+35.66>172xxxxxxxxxxxx
@110516060032<M02m02-7959=+35.30,+35.30,+35.30,+35.30,+35.33,+35.33,+35.34,+35.34,+35.37,+35.37,+35.37,+35.37,+35.37,+35.37,+35.40,+35.40,+35.39,+35.39,+35.41,+35.41,+35.41,+35.41,+35.39,+35.39,+35.34,+35.34,+35.32,+35.32,+35.29,+35.29,+35.26,+35.26,+35.23,+35.23,+35.22,+35.22,+35.21,+35.21,+35.19,+35.19,+35.19,+35.19,+35.19,+35.19,+35.19,+35.19,+35.19,+35.19,+35.19,+35.19,+35.18,+35.18,+35.19,+35.19,+35.18,+35.18,+35.18,+35.18,+35.18,+35.18,+35.18,+35.18,+35.16,+35.16,+35.16,+35.16,+35.16,+35.16,+35.16,+35.16,+35.16,+35.16,+35.18,+35.18,+35.18,+35.18,+35.16,+35.16,+35.18,+35.18,+35.18,+35.18,+35.16,+35.16,+35.18,+35.18,+35.18,+35.18,+35.16,+35.16,+35.16,+35.16,+35.16,+35.16,+35.18,+35.18,+35.16,+35.16,+35.16,+35.16,+35.16,+35.16,+35.16,+35.16,+35.18,+35.18,+35.16,+35.16,+35.18,+35.18,+35.19,+35.19,+35.21,+35.21,+35.22,+35.22,+35.23,+35.23,+35.25,+35.25>074xxxxxxxxxxxx
@110516060033<M02m04-7959=+35.47,+35.47,+35.47,+35.47,+35.43,+35.43,+35.48,+35.48,+35.40,+35.40,+35.44,+35.44,+35.51,+35.51,+35.47,+35.47,+35.44,+35.44,+35.44,+35.44,+35.51,+35.51,+35.48,+35.48,+35.44,+35.44,+35.51,+35.51,+35.46,+35.46,+35.46,+35.46,+35.46,+35.46,+35.48,+35.48,+35.48,+35.48,+35.44,+35.44,+35.48,+35.48,+35.41,+35.41,+35.41,+35.41,+35.48,+35.48,+35.47,+35.47,+35.44,+35.44,+35.39,+35.39,+35.46,+35.46,+35.44,+35.44,+35.40,+35.40,+35.44,+35.44,+35.37,+35.37,+35.40,+35.40,+35.39,+35.39,+35.41,+35.41,+35.41,+35.41,+35.37,+35.37,+35.43,+35.43,+35.36,+35.36,+35.37,+35.37,+35.41,+35.41,+35.41,+35.41,+35.39,+35.39,+35.34,+35.34,+35.43,+35.43,+35.41,+35.41,+35.39,+35.39,+35.44,+35.44,+35.37,+35.37,+35.37,+35.37,+35.37,+35.37,+35.43,+35.43,+35.44,+35.44,+35.40,+35.40,+35.44,+35.44,+35.40,+35.40,+35.41,+35.41,+35.47,+35.47,+35.46,+35.46,+35.44,+35.44>162xxxxxxxxxxxx
As you can see, this needs pattern matching.. Hence we used JSP's with String Tokenizers and JDBC for uploading the values..
Specifications of our system are :
Apache Tomcat 5.0
Oracle 10g XE
and JDK 1.6.0_02
For which we could not find a suitable SQL developer hence we used PL/SQL commands instead..
The upload form we used contained a basic BROWSE button that redirected to the following JSP when a file was selected
Collapse | Copy Code
<%@ page import="javax.servlet.http.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.StringTokenizer" %>
<%@ page import="javax.servlet.ServletException" %>
<%@ page import="javax.servlet.http.HttpServlet" %>
<%@ page import="javax.servlet.http.HttpServletRe… %>
<%@ page import="javax.servlet.http.HttpServletRe… %>
<% int i,p=0,q=0,a,b,c,d,e,f,n=0,k=0,l=0;
String r,code;
String avi;
String str1;
String str2;
String str3;
String name=request.getParameter("datafile");
String data[]=new String[4000];
String data1[]=new String[4000];
String data2[]=new String[4000];
out.println(name);
FileInputStream in = new FileInputStream(name);
Class.forName("oracle.jdbc.driver.Orac…
Connection con=DriverManager.getConnection("jdbc:or…
conn.setAutoCommit( false );
Statement stmt=con.createStatement();
BufferedReader br = new BufferedReader(new InputStreamReader(in,"UTF-8"));
String strLine;
while ((strLine = br.readLine())!= null)
{
if(strLine.startsWith("@"))
{
a=strLine.indexOf("=");
b=strLine.indexOf(">");
c=strLine.indexOf("<");
d=strLine.indexOf("-");
code=strLine.substring(c+1,d);
if(code.equals("M02m00")) // for air temp level1
{
if(!(a<0))
{
i=0;
String line=strLine.substring(a+1,b);
StringTokenizer st = new StringTokenizer(line,"=,>");
while(st.hasMoreTokens())
{
data1[i]=st.nextToken();
i++;
}
}
}
if(code.equals("M02m02")) // airtemp level 2
{
if(!(a<0))
{
i=0;
String line=strLine.substring(a+1,b);
StringTokenizer st = new StringTokenizer(line,"=,>");
while(st.hasMoreTokens())
{
data[i]=st.nextToken();
i++;
}
}
}
if(code.equals("M02m04")) // for airtemp level3
{
if(!(a<0))
{
i=0;
String line=strLine.substring(a+1,b);
StringTokenizer st = new StringTokenizer(line,"=,>");
while(st.hasMoreTokens())
{
avi=st.nextToken();
data2[i]=st.nextToken();
i++;
n++;
}
}
}
out.println(n);
}
while(k<n)
{
str1=data1[k];
str2=data[k];
str3=data2[k];
out.println(str1);
ResultSet Rs1=stmt.executeQuery(" Insert /*+ APPEND_VALUES */ into AIRTEMP(LEVEL1,LEVEL2,LEVEL3) values('"+str1+"','"+str2+"','"+str3+"')…
k++;
}
}
%>
The difficulty we have is that this code cannot upload more than 500 records into the table and that too it doesnt upload properly Plz help