raja maharaja

Greenhorn
+ Follow
since Aug 15, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by raja maharaja

Jeanne Boyarsky wrote:Raja,
The connection is declared in yiour main method. The thread's run method has no way to know about it. How about extracting that logic into a helper method so both main() and run() can obtain a connection?

Also, you'll want to close your resources in a finally block. Right now the code has a connection leak.





can you tell me about that helper method how can i write that , so that my logic can be distributed to both main and run methods???
now iam getting only one error at line number 52 in the below code.
can you tell me should i make another class in which i can declare connection object and if i extend that, can that scope will be available to entire class of this code.
this is my error in the below code,please guide me.


Campbell Ritchie wrote:That is a new error, caused by your adding an unnecessary throws declaration (in the wrong place).




but if i remove that throws declaration from there ,iam getting some more errors.
please tell me what i can do to remove thsi error.

Campbell Ritchie wrote:You don't have a pst variable anywhere in scope at that time. And I have already given a hint about the other error.





ya i have resolved that error,but now one error left


please tell me what i should do to correct this error

Campbell Ritchie wrote:And what are the errors? Are they compile-time or run-time errors? Look through the Connection interface and check the names of all methods very carefully.






two errrors are compiletime errors

and these are the errors


please tell me what mistake i have done , i wrote syntax correctly, please check
iam getting two errors in this code
one is at prepared sttement object
and the other at pst.executeUpdate()
these two errors are coming at lines 52 & 72 of the below code
here in this code whenever the result of ping is "request timed out " iam storing the date of that in the database and that iam doing with prepared statememt object.
but it is showing error at those two lines.

please tell me what mistake i have done???

hello,
this is my code, in this i want to establish a connection to the database using jdbc type-1 driver,my code is about giving "ping" to the local host and storing the results in to the file.after storing the results in to the file, i want to read the file and search for the result "Request timed out" , whenever i encounter this then i should establish connection with the database and store the "date and time" of this result in the database.here in this once if you enter the IPAddress then it enters in to the infinite loop and gives ping continously.
can anyone please help me out, iam confused in how to enter the date and time into the database???
please help me

import java.net.;
import java.io.;
import java.util.*;
class MyThread extends Thread
{
Date d=new Date();
String s=d.toString();
String result,res;
String ip;
MyThread(String ip)
{
this.ip=ip;
}



public void run()
{
for(; ;)
{
try
{
Process p = Runtime.getRuntime().exec("ping " ip );
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedWriter bw = new BufferedWriter(new FileWriter("out.txt",true));
bw.newLine();
bw.write(s);
bw.newLine();
while ((result = in.readLine()) != null)
{
bw.write(result);
bw.newLine();
}
in.close();
bw.close();
}
catch (IOException ioe)
{
System.err.println("IOEXception occured : " ioe.getMessage());
}


}
}

public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter IP Address: ");
String i=br.readLine();
MyThread t=new MyThread(i);
Thread t1= new Thread(t);
t1.start();


}
}