I'm using : Windows 2000,jdk1.3.0_02,Interbase6.5,Interclient 2.0
I get this following error:
Exception creating the database connection: interbase.interclient.CommunicationException: [interclient] Communication error: A socket exception occurred while trying to establish a socket connection to server localhost.
The message of the SocketException is "Connection refused: connect".
See API reference for exception interbase.interclient.CommunicationException
java.lang.NullPointerException
at database.<init>(database.java:66)
at database.main(database.java:76)
Exception in
thread "main"
And my
java file is as follows :
import java.io.*;
import java.sql.*;
public class database {
static Connection con;
public database() {
try {
// Resolve the
JDBC driver class:
Class.forName("interbase.interclient.Driver");
// The following line actually starts up the database connection:
con = DriverManager.getConnection("jdbc:interbase://localhost/c:/ecole/sgbdr/SPJ_2001.gdb","sysdba","masterkey");
} catch ( ClassNotFoundException cnfe ) {
// Report the problem to the standard error stream:
System.err.println("Couldn't locate the driver class: "+cnfe);
} catch ( SQLException se ) {
// Report the problem to the standard error stream:
System.err.println("Exception creating the database connection: "+se);
}
try {
String id_s = null;
String sname= null;
String status= null;
String city= null;
String sql = "SELECT * from S";
Statement sment = con.createStatement();
ResultSet rs = sment.executeQuery(sql);
if ( rs.next() ) {
// Calls to rs.next() position the result set to the next available row.
// You'd use 'while ( rs.next() )' in the case that multiple rows may be returned.
id_s = rs.getString("id_s"); /* the column index can also be used */
sname = rs.getString("sname");
status = rs.getString("status");
city = rs.getString("city");
} else {
System.out.println("The row does not exist in the database");
}
rs.close(); /* Perhaps unnecessary as the next line will close the ResultSet too */
sment.close(); /* But some drivers have resource problems, so its to be safe */
} catch ( SQLException se ) {
// Report the problem to the standard error stream:
System.err.println("Exception performing query: "+se);
} finally {
try {
con.close();
} catch ( SQLException se ) {
System.err.println("Exception performing close: "+se);
}
}
}
public static void main(String args[]) throws SQLException,Exception,ClassNotFoundException {
new database();
}
}
Any help help would be appreciated .Thanks