I have connected my two laptops using a cat5 cross ethernet cable. Both have linux ubuntu installed.
Lappi 1: $ ifconfig eth0 192.168.1.16 up
Lappi 2: $ ifconfig eth0 192.168.1.17 up
both connected via wired ethernet connection
ping lappi 1: $ ping 192.168.1.17
give bytes means working
ping lappi 2: $ ping 192.168.1.16
working
lappi 1 has oracle xe 10g installed on it.
I want to fetch some rows using lappi-2 from oracle database at lappi-1.
Here is code
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class servertest
{
public void test() throws ClassNotFoundException, SQLException
{
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@192.168.1.16:1521:XE","scott","tiger");
Statement stmt = conn.createStatement();
String query = "select email_to from createemail";
ResultSet rset = stmt.executeQuery(query);
while(rset.next())
{
System.out.println(rset.getString(0));
}
}
public static void main(String args[]) throws ClassNotFoundException, SQLException
{
servertest obj = new servertest();
obj.test();
}
}
It doesn’t give me any error. but it also doesn’t retrieve any rows. Sometimes I get an error “connection could not be established”…(occasionally) ]
I don’t see any problem in the code. Maybe it does not return rows because there are not any. And it probably returns connection error, because the link is really down (maybe the cable is damaged…).
Java has very good error reporting, just read the message carefully. If it reports it cannot connect, be 99% sure that it is the network problem. If there are no rows, double check that you are selecting the right table etc.
Please follow Java Naming Conventions: class names start with uppercase.