I am trying to copy data from text file into my database which I created through derby using netbeans. The app keeps running without terminating nor it is showing any error it just keeps running while copying null values in database. Below is the code and I have also attached screenshot of output. Kindly help me with this.
try{
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
connection = DriverManager.getConnection(urlanddatabasename,userName,password);
if(connection==null)
{
System.out.println("no connection");
}
else
{
System.out.println("connection established");
}
String fileName = "C:\\Users\\MPC\\Desktop\\wslist.txt";
File file = new File(fileName);
Scanner inputStream = new Scanner(file);
ps = connection.prepareStatement("INSERT INTO AB.WSLIST"
+"(SERVICEID, WSDLADDRESS, SERVICEPROVIDER, IPADDRESS, COUNTRY, IPNO, AAS, LATITUDE, LONGITUDE) "
+ "values(?, ?, ?, ?, ?, ?, ?, ?, ?)");
String[] ar = new String[9];
while(inputStream.hasNext()){
String idd = ar[0];
String wsd = ar[1];
String sp = ar[2];
String ip = ar[3];
String c = ar[4];
String ipn = ar[5];
String as = ar[6];
String lat = ar[7];
String lg = ar[8];
ps.setString(1,idd);
ps.setString(2,wsd);
ps.setString(3,sp);
ps.setString(4,ip);
ps.setString(5,c);
ps.setString(6,ipn);
ps.setString(7,as);
ps.setString(8,lat);
ps.setString(9,lg);
int i=ps.executeUpdate();
if(i!=0) {
System.out.println("Record inserted");
}
else{
System.out.println("Record not inserted");
}
connection.commit();
}
}
finally{ try{
ps.close();
}
catch (SQLException ex) {
ex.printStackTrace();
}
try {
connection.close();
} catch(SQLException e) {
e.printStackTrace();
}
}
}