• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hello i need help in establishing connection with database througgh jdbc

 
raja maharaja
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();


}
}
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raja. You haven't shown us any database or jdbc code. What is your exact problem? Do you know how to start using jdbc?

Regards, Jan
 
Campbell Ritchie
Sheriff
Posts: 51468
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch
Please use the CODE button and maintain indentation; it would make your code much easier to read.
 
Charbel Keyrouz
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact the idea is not clear on what you are trying to do but there is an error in the following line:


replace it with this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic