Hello im stuck with my programm, I'm newbie at programming, but I have to finish this programm for my school project. I only use youtube tutorials, but in the end there is not enought info so im asking here for help.
Basicaly what this programm does is take ip addreses from Database and pings them, if it fails to ping it displays ip address in one table if pingable it dispalys in other.I hope you understand what im trying to do here, and plz don't say that my question is not clear, cause I dont think I can explain it better,its pretty hard cause I hardly understand programming language.
private void browseActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser chooser = new JFileChooser();
File F = new File ("c:/");
File NameDir, NamePath;
int Checker;
chooser.setCurrentDirectory(F);
chooser.setDialogTitle ("Choose db");
Checker = chooser.showOpenDialog(null);
if (Checker == JFileChooser.APPROVE_OPTION){
NameDir = chooser.getCurrentDirectory();
NamePath = chooser.getSelectedFile();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = NamePath.getAbsolutePath();
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}";
Connection con = DriverManager.getConnection( database ,"","");
//I am using Access Database thats why all this connection code ^^
Statement s = con.createStatement();
s.execute("SELECT AgIP FROM Agents ");
ResultSet rs = s.getResultSet();
if (rs != null)
while ( rs.next()){
String sampleString = rs.getString(1);
boolean reachable = false;
reachable=(InetAddress.getByName(sampleString).isR eachable(1000));
if (reachable==true){
for (int i = 0;i <jTable1.getRowCount();i++){ //This place is not right for sure
jTable1.getModel().setValueAt(sampleString, i, 0);
}
}
else{
for (int e = 0;e <jTable2.getRowCount();e++){
jTable2.getModel().setValueAt(sampleString, e , 0);
}
}
}
}
catch (Exception err) {
System.out.println("ERROR: " + err);
}
}
}
Hope it is enough info.In picture I added there is explained deeper what im trying to achieve.