I want to read data from a txt file and insert it into my database, but my code only insert 16 lines and stops. The txt file has 200 lines. I don't know what I'm doing wrong. Any help will be appreciated. Thanks in advance
Here is my code:
public static void main(String[] args) throws ClassNotFoundException, SQLException
{
String date;
String heure;
String parametre;
String valeur;
PreparedStatement ps = null;
Connection con = null;
ResultSet rs = null;
try
{
BufferedReader br = new BufferedReader(new FileReader("Data_Station_1.txt"));
String username = "postgres";
String pwd = "elghorrim";
String connurl = "jdbc:postgresql://localhost:5432/BDS_CSF_AuqliteEau";
con = DriverManager.getConnection(connurl, username, pwd);
Class.forName("org.postgresql.Driver");
String line = null;
while ((line = br.readLine()) != null)
{
String tmp[] = line.split(",");
date = tmp[0];
heure = tmp[1];
parametre = tmp[2];
valeur = tmp[3];
System.out.println(date + "\t" + heure + "\t" + parametre + "\t" + valeur);
String sql =
"INSERT INTO resultat (date_resultat,valeur,code_pc,code_parametre,heure_resultat) values ('"
+ date + "','" + valeur + "','1','" + parametre + "','" + heure +
"')";
ps = con.prepareStatement(sql);
ps.executeUpdate();
}
br.close();
con.close();
ps.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}