472,337 Members | 1,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,337 software developers and data experts.

MYSQL Problem

16
Dear All,

I am facing a very peculiar problem. I am reading a CSV file from my JSP code and trying to insert them into MYSQL database. the program first reads a line and then splits it into words using the split function and then inserts them into different fields of the database. But the problem is that the JSP [age shows that the records have been inserted but actually when we look into the database althugh the records have been inserted but they are empty that is without values.

This is the code that i have written


<%@ page import= "java.io.*"%>
<%@ page import="java.util.StringTokenizer"%>
<%@ page import="java.util.*"%>
<%@ page import= "java.util.Date" %>
<%@ page import= "java.text.DateFormat" %>
<%@ page import= "java.text.SimpleDateFormat" %>
<%@ page language="java" %>
<%@ page import="java.lang.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import= "java.io.File"%>
<%@ page import ="java.io.*"%>
<%@ page import ="java.awt.*"%>
<%@ page import ="java.awt.Component.*"%>
<%@ page import ="java.awt.event.*"%>
<%@ page import ="javax.swing.*"%>
<%@ page import ="java.sql.ResultSet.*"%>
<%@ page import ="java.sql.Statement"%>

<%@ page import="java.text.*,java.io.*,java.util.*,java.uti l.StringTokenizer,java.io.BufferedReader,java.io.F ileReader,java.sql.*,java.util.StringTokenizer,jav a.io.BufferedReader,java.io.FileReader"%>

<%


File file = new File("C:\\Documents and Settings\\nripraj.INFOBASE\\Desktop\\Earnings_1106 00_0_0_200702.csv");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;

try {



fis = new FileInputStream(file);

// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);

// dis.available() returns 0 if the file does not have more lines.

while (dis.available() != 0) {

// this statement reads the line from the file and print it to
// the console.
String line = dis.readLine();
out.println("Data is:"+line);
//int n = line.indexOf("",0);
String token[];

token=line.split(" ");




DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date curdate = new Date();


Class.forName("org.gjt.mm.mysql.Driver").newInstan ce(); //driver for mysql database.


Connection con= null;

ResultSet rs = null;

con = DriverManager.getConnection("jdbc:mysql://localhost/rptgenerator","generator", "generator");

String dt = dateFormat.format(new Date());
String field1="";
String field2="";
String field3="";
String field4="";
String field5="";
String field6="";

for (int i=0;i<token.length;i++)
{
if (i==0)
{
field1=token[i] ;
out.println(field1);
}
else if (i==1)
{
field2=token[i] ;
out.println(field2);
}
else if (i==2)
{
field3=token[i] ;
out.println(field3);
}
else if (i==3)
{
field4=token[i] ;
out.println(field4);
}
else if (i==4)
{
field5=token[i] ;
out.println(field5);
}
else if (i==5)
{
field6=token[i] ;
out.println(field6);
}

}


String query = "insert into xyz values(?,?)";
PreparedStatement pstmt = con.prepareStatement(query);
pstmt.setString(1, dt);
pstmt.setString(2, field1);
pstmt.setString(3, field2);
pstmt.setString(4, field3);
pstmt.setString(5, field4);
pstmt.setString(6, field5);
pstmt.setString(7, field6);*/
pstmt.setString(1, token[1]);
pstmt.setString(2, "Compare");

int l = pstmt.executeUpdate();
out.println("Updated Records:"+l);


%>
<br><br><br>
<%

}
out.println("Input Successful");
// dispose all the resources after using them.

fis.close();
bis.close();
dis.close();

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}catch (Exception e) {

out.println(e);
e.printStackTrace();
}

%>


Any help will be appreciated..



Thanks & Regards
Nrip Raj Jain
Feb 8 '07 #1
0 1618

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: JL | last post by:
Platform: Linux Red Hat RHEL 3 (and red hat 9) Installed MySQL from source. As a matter of fact, installed all LAMPS from source, and the mysql...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been...
3
by: Kirk Soodhalter | last post by:
Hi, This started as a phpmyadmin problem, but has somehow morphed into a mysql problem. I don't know how to fix it. I am posting the...
0
by: Plymouth Acclaim | last post by:
Hi guys, We have a problem with Dual AMD64 Opteron/MySQL 4.0.18/Mandrake 10 for a very high volume site. We are evaluating the performance on our...
1
by: Alex Hunsley | last post by:
I am trying to install the DBD::mysql perl module. However, it claims I need mysql.h: cpan> install DBD::mysql CPAN: Storable loaded ok Going...
1
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. ...
1
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore...
10
by: Caffeneide | last post by:
I'm using a php script which performs three xml queries to other three servers to retrieve a set of ids and after I do a query to mysql of the kind...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.