i want to read the txt file content and insert that into my sql table.
I did this by coding but it is showing some error. Also tried by query but it is showing null in the table.
query -
INSERT INTO patent_uspto_tmp (pinv) VALUES (LOAD_FILE('/home/gaurav/Documents/pinv.txt'));
code -
try{
String arr[]=null;
String outputFile = "/home/gaurav/Documents/pinv.txt";
FileReader fileReader = new FileReader(outputFile);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String inputLine;
List<String> lineList = new ArrayList<String>();
while ((inputLine = bufferedReader.readLine()) != null) {
lineList.add(inputLine);
}
fileReader.close();
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/patent","root","india2000");
for (int i = 1;i<outputFile.length();i++)
{
arr[i]=outputFile.valueOf(i);
PreparedStatement ps = (PreparedStatement) con.prepareStatement("insert into patent_uspto_tmp (pinv) values(?)");
ps.setString(1,arr[i]); // set the param here with the some value
ps.executeUpdate();
con.commit();
con.close();
}
}
catch(Exception e)
{
throw new RuntimeException(e);//System.out.println(e);
}
}
}
error - null pointer exception