I have crated a java jframe program that allows you to input a csv file and then upload it to a local database however I am having trouble inserting all the data into the database. Any ideas on where I may be going wrong?
try{
BufferedReader br=new BufferedReader(new FileReader(filename1));
String line;
while((line=br.readLine())!=null){
String[]value=line.split(",");//Seperator
filename1 is the selected csv file from a jFilechooser.
String sql="insert into websitehistory (Date, URL, VisitCount) "
+ "values (?,?,?)";
pst=conn.prepareStatement(sql);
pst.setString(1, value[0]);
pst.setString(2, value[1]);
pst.setString(3, value[2]);
Here is mysql query of inserting the separated values into the database
This is my table structure:
Date Varchar(244)
URL VarChar(244)
VisitCount VarChar(244)
And the type of data I would like to insert is:
31/01/2014 15:26:00, https://www.youtube.com/, 13
31/01/2014 15:25:00, https://www.youtube.com/, 17
Any help is much appreciated
?instead of each'"+value[i]+"'in your sql query. This way you can later replace?with correct value usingsetXXX(number,value).