on 03-04-2005 12:45 AM
Hello,
I'm trying to set a timer in a Java application that connect to SAP every 10 minutes. But I got some trouble doing this. Could any one help me out? BELOW IS THE CODE:
import com.sap.mw.jco.*;
public class TutorialConnect1 extends Object {
JCO.Client mConnection;
long timeout = (1000*60)*10; // 1000ms = 1sec*60 = 1min*10 = 10min
for(int i=0;i<1000;i++)
{
public TutorialConnect1() {
try{
mConnection = JCO.createClient("900",//SAP Cleint
"test",//userid
"test",//password
"EN",//language
"test",//host name
"00");// system number
mConnection.connect();
System.out.println(mConnection.getAttributes());
mConnection.disconnect();
}
catch (Exception ex){
ex.printStackTrace();
System.exit(1);
}
}
// start of the Sleep Timeout
try
{
Thread.sleep(timeout);
}catch(InterruptedException e)
{
System.out.println("main thread interrupted");
}
}// for
public static void main(String args[]) {
TutorialConnect1 app = new TutorialConnect1();
}
}
THIS IS THE ERROR MESSAGE:
java.lang.Error: Unresolved compilation problem:
at TutorialConnect1.main(TutorialConnect1.java:19)
Exception in thread "main"
Line 19 correspond to this "mConnection = JCO.createClient( )"
Hi Rudolph,
You are trying to create a constructor inside a for loop which is not possible in Java.
I'm dumping the modified code here which I have tested and works:
import com.sap.mw.jco.*;
public class TestJCO {
JCO.Client mConnection;
long timeout = (1000*10); // 10 sec
public boolean connect() {
for(int i=0;i<1000;i++)
{
System.out.println("In for loop");
try{
mConnection = JCO.createClient("00",//SAP Cleint
"user",//userid
"pass",//password
"EN",//language
"host",//host name
"00");// system number
mConnection.connect();
System.out.println(mConnection.getAttributes());
mConnection.disconnect();
}
catch (Exception ex){
ex.printStackTrace();
System.exit(1);
}
try
{
Thread.sleep(timeout);
}catch(InterruptedException e)
{
System.out.println("main thread interrupted");
}
}
return true;
}
public TestJCO() {
}
public static void main(String args[]) {
TestJCO app = new TestJCO();
boolean bool = app.connect();
System.out.println(bool);
}
}
Hope it helps.
Regards,
Manish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.