aspose file tools*
The moose likes JDBC and the fly likes hello i need help in establishing connection with database througgh jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "hello i need help in establishing connection with database througgh jdbc" Watch "hello i need help in establishing connection with database througgh jdbc" New topic
Author

hello i need help in establishing connection with database througgh jdbc

raja maharaja
Greenhorn

Joined: Aug 15, 2009
Posts: 7
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

Joined: Dec 20, 2006
Posts: 2503
    
    8

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


OCUP UML fundamental and ITIL foundation
youtube channel
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39408
    
  28
Welcome to JavaRanch
Please use the CODE button and maintain indentation; it would make your code much easier to read.
Charbel Keyrouz
Ranch Hand

Joined: Jun 10, 2005
Posts: 46
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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hello i need help in establishing connection with database througgh jdbc