hello, i have written a program which selects each record in the database-table(having ip,status and other fields) pings to that ip and if a reply is obtained then the program establishes a socket conn b/w another comp and exchanges information,if info is exhanged then nothing is to be done to the db else the status field is set to '0' and if the request has timed out for the ping msg then i need to delete the line. this whole process has to go infinite times. the program works well but suddenly it stated invalid cursor state and hangs up. can anyone tel me wat is wrong?
the server side code is this

package server;
import project.*;
import java.io.*;
import java.net.*;
import java.lang.Object.*;
import java.sql.*;
import java.net.ServerSocket.*;
import java.lang.String.*;


public class db {
private static String dbip;
private static String host;
private static String dbmac;
private static int dbport;


public static void main(String a[]) throws ClassNotFoundException, SQLException, InterruptedException
{
ResultSet resad;
Connection connad;
Statement statad;
int i=0;
String array[] = new String[10];
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connad = DriverManager.getConnection("jdbc:odbc:MS Access Database");
statad = connad.createStatement();
resad = statad.executeQuery("SELECT * FROM clients_online");
while(true){



try
{              // resad.refreshRow();
resad.next();
array[0]=resad.getString(1);//ip
array[1]=resad.getString(2);//ma
array[2]=String.valueOf(resad.getInt(6));//adapt port
array[3]=resad.getString(7);//username
System.out.println("adaptport from db:"+array[2]);
System.out.println("ip from db:"+array[0]);
System.out.println("mac from db:"+array[1]);
System.out.println("username from db:"+array[3]);


dbip=array[0];
dbmac=array[1];
dbport=Integer.valueOf(array[2]);
host=array[3];
int flag=ping(dbip);int k=0;
if(flag==1)
{
System.out.println("ON machine---->"+array[3]);


k=server.db.probe(dbip,dbmac,dbport,host);
if(k==1)
{
System.out.println("Safemits started");
System.out.println("--------------------------");
Connection conn;
Statement stat;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:MS Access Database");
stat = conn.createStatement();
stat.execute("update clients_online set status ='1' where ip='"+dbip+"'");
conn.close();
stat.close();
}


}
else
{
System.out.println("OFFLINE");
System.out.println("--------------------------");
Connection conn;
Statement stat;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:MS Access Database");
stat = conn.createStatement();
stat.execute("delete * from clients_online where ip='"+dbip+"'");
conn.close();
stat.close();
}


}



catch(Exception x)
{


String d[]=null;
//  connad.close();
//   statad.close();
// resad.close();


System.out.println("No records in db..restarting");
System.out.println(x);
//System.out.println("Unable to connect to database");
Thread.sleep(8000);
db.main(d);



}


++i;
System.out.println("RECORD:"+i);



}
}


private static int ping(String ip) throws IOException
{
String cmd = "ping "+ip;
Runtime runtime = Runtime.getRuntime();
Process p=runtime.exec(cmd);//Running ipconfig -all in cmd prompt
InputStreamReader isr=new InputStreamReader(p.getInputStream());//Readind the STDOUT
BufferedReader brd = new BufferedReader(isr);//Placing read info in buffer
String line=null;
int flag=0;
while(true)
{
line=brd.readLine();
if(line.startsWith("Reply"))
{
flag=1;
break;
}
if(line.startsWith("Request"))
{
flag=0;
break;
}
}


if(flag==1)
return 1;
else
return 0;
}


private static int probe(String recip,String recmac,int serverPort,String hostname) throws ClassNotFoundException, SQLException
{


try{
hostname=hostname.substring(0,3);
InetAddress ipAddress = InetAddress.getByName(hostname);
Socket socket = new Socket(ipAddress, serverPort);
OutputStream sout = socket.getOutputStream();
DataOutputStream out = new DataOutputStream(sout);
InputStream sin = socket.getInputStream();
DataInputStream in = new DataInputStream(sin);


//BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
//String line = null;
System.out.println();
int t=1;
String ip = null;String mac=null;
while(t==1)
{


out.writeUTF("send ip and mac");
mac= in.readUTF();
ip= in.readUTF();


System.out.println("recieved from client :"+mac);
System.out.println("recieved from client :"+ip);


Thread.sleep(10000);
t=0;
}
socket.close();


System.out.println("recd mac :"+mac+" ip "+ip);
System.out.println("have mac :"+recmac+" ip "+recip);
if(recip.equals(ip) && recmac.equals(mac))
{


return 1;
}
else return 0;


}
catch(Exception s)
{      System.out.println("Safemits not started");
System.out.println("--------------------------");
Connection conn;
Statement stat;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:MS Access Database");
stat = conn.createStatement();
stat.execute("update clients_online set status ='0' where ip='"+recip+"'");
conn.close();
stat.close();
System.out.println("Error here in probe:"+s.getMessage());
return 0;
}


}


}

Hi This problems occurs becuase of the data base and not your code. instead of MA Access and jdbcodbc driver try using mysql and mmmsql driver . The problem should not occur. Ms Access does not support concurrent access by 2 users . You care creating 2 conenctions to the db . I used to face similar kind of issue. Most of the times it doent give problem but one caanot be sure when it will fail. Also read Ms Access documentaion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.