在将数据转储到表中时需要帮助 [英] Need help with dumping data into tables
问题描述
我们需要上载到项目表中的数据文件是一个外部".CSV"文件,其文本格式如下(这只是其1/20的一部分.这些,将近20组具有不同值的此类数据)
@ 110519120031< m02m00-0315> 160xxxxxxxxxxxx
@ 110519120032< m02m02-0315> 204xxxxxxxxxxxx
@ 110519120033< m02m04-0315> 155xxxxxxxxxxxx
如您所见,这需要模式匹配.因此,我们将JSP与String Tokenizers和JDBC一起使用来上传值.
我们系统的规格为:
Apache Tomcat 5.0
Oracle 10g XE
和JDK 1.6.0_02
为此,我们找不到合适的SQL开发人员,因此我们改用PL/SQL命令.
上传表格我们使用包含一个基本的浏览按钮重定向到下面的JSP时选择
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)
@110519120031<m02m00-0315>160xxxxxxxxxxxx
@110519120032<m02m02-0315>204xxxxxxxxxxxx
@110519120033<m02m04-0315>155xxxxxxxxxxxx
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
<%@ 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.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>
<% 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.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","mblm","1321213");
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++;
}
}
%>
我们遇到的困难是该代码无法将多于500条记录上载到表中,并且也无法正确上载Plz帮助
[edit] SHOUTING已删除,<和> HTML编码,伪造的结束标记已删除-OriginalGriff [/edit]
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
[edit]SHOUTING removed, < and > HTML encoded, spurious closing tags removed - OriginalGriff[/edit]
推荐答案
我可以在其中看到相同的代码部分.还有-没有更优雅的方式做到这一点吗?看起来有点固定".
该代码不负责500条记录的限制.您的数据库必须是ether,否则您在pos上可能有错误的记录. 501.
I can see identical code parts in there. Also - isn''t there a more elegant way to do this? Looks a bit "fixed".
The code is not responsible for the 500 record limit. Must be ether your database or you might have a false record on pos. 501.
这篇关于在将数据转储到表中时需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!