Meaningless Drivel is fun!*
The moose likes Distributed Java and the fly likes RMI application connection issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI application connection issue" Watch "RMI application connection issue" New topic

RMI application connection issue

Olakunle Oladipo Oni

Joined: Aug 28, 2008
Posts: 18
I cannot resolve ConnectException i'm having with an RMI application I'm working on. The client application kept giving a phrase like "connection refused to host: taking the appropriate steps such as
(1) starting the RMI registry
(2) starting the server application
(3) starting the client application to connect it with the server application.

I want to build and test the application first on my local system before doing anything further. Both Server and client programs reside in one computer and in the same folder. The OS is windows 7. what prompted my posting this is because i've tried the options i'm aware of like:
(1) referencing the system variable java.rmi.server.hostname when running the server application
(2) Editing the \host folder in my OS

I kept recieving the same error message from the client application. I'll appreciate is someone could give advice on the way out. There is no issue with compiling both programs: This application relies on the client calling the server program to send the data entered on the client side to a database:

The client app is shown below:

mport javax.swing.*;
import java.rmi.*;
import java.awt.event.*;
import java.awt.*;

public class Aclienty
static JFrame frame;
static JPanel panel,panel1;
JLabel labelAuthorID,labelLastName,labelFirstName,labelPhone,labelAddress,labelCity,labelState,labelZip;
JTextField textAuthorID,textLastName,textFirstName,textPhone,textAddress,textCity,textState,textZip;
JButton submit;
static String authorID;
static String lastName;
static String firstName;
static String phone;
static String address;
static String city;
static String state;
static String zip;

public Aclienty()
frame = new JFrame("Earnest Publishing House");
panel = new JPanel();
panel1 = new JPanel();
panel.setLayout(new GridLayout(8,2));
panel1.setLayout(new GridLayout(1,1));
frame.getContentPane().setLayout(new BorderLayout());

labelAuthorID = new JLabel("Author ID");
labelLastName = new JLabel("Last Name");
labelFirstName = new JLabel("First Name");
labelAddress = new JLabel("Address");
labelPhone = new JLabel("Phone");
labelCity = new JLabel("City");
labelState = new JLabel("State");
labelZip = new JLabel("Zip");

textAuthorID = new JTextField(5);
textLastName = new JTextField(15);
textFirstName = new JTextField(15);
textPhone = new JTextField(10);
textAddress = new JTextField(50);
textCity = new JTextField(10);
textState = new JTextField(10);
textZip = new JTextField(6);

submit = new JButton("Submit");

ButtonListener blisten = new ButtonListener();
frame.getContentPane().add(new JPanel(), BorderLayout.WEST);
frame.getContentPane().add(new JPanel(), BorderLayout.EAST);
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.getContentPane().add(panel1, BorderLayout.SOUTH);
class ButtonListener implements ActionListener
public void actionPerformed(ActionEvent evt)
JButton source = (JButton)evt.getSource();
MyDialog myDialog;
AuthorServer server = (AuthorServer)Naming.lookup("rmi://");
authorID = textAuthorID.getText();
lastName = textLastName.getText();
firstName = textFirstName.getText();
phone = textPhone.getText();
address = textAddress.getText();
city = textCity.getText();
state = textState.getText();
zip = textZip.getText();

String str = server.insertDetails(authorID, lastName, firstName, phone, address, city, state, zip);
myDialog = new MyDialog(frame,"Inserted Successfully");
myDialog = new MyDialog(frame,"No record inserted");
catch(Exception e)
public static void main(String[]args)
new Aclienty();
class MyDialog extends Dialog implements ActionListener
MyDialog(Frame parent, String title)
setLayout(new FlowLayout());
add(new JLabel(title));
JButton buok = new JButton("OK");
public void actionPerformed(ActionEvent evt)

The server app is shown below:

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.UnicastRemoteObject;
import java.sql.*;
import java.sql.Connection;

public class AuthorServerImpl extends UnicastRemoteObject implements AuthorServer
static ResultSet result;
static Connection con;
static PreparedStatement stat;

public AuthorServerImpl() throws RemoteException
public String insertDetails(String authorID,String lastName,String firstName,String phone,String address,String city,String state,String zip) throws RemoteException
int rowsAffected = 0;
String sReturn = "fail";

con = DriverManager.getConnection("jdbc:mysql://localhost:3306/publishing","thepubs","eansbok");
stat = con.prepareStatement("insert into authors(AuthorID,Last_Name,First_Name,Phone,Address,City,State,Zip)values(?,?,?,?,?,?,?,?)");
stat.setString(1, authorID);
stat.setString(2, lastName);
stat.setString(3, firstName);
stat.setString(4, phone);
stat.setString(5, address);
stat.setString(6, city);
stat.setString(7, state);
stat.setString(8, zip);
rowsAffected = stat.executeUpdate();
if(rowsAffected > 0)
sReturn = "success";
catch(Exception ex)
System.out.println("Error at value insert" + ex);
return sReturn;
public static void main(String[]args)
System.setSecurityManager(new RMISecurityManager());

AuthorServerImpl instance = new AuthorServerImpl();
Naming.rebind("Authorserver", instance);
System.out.println("Server Registered");

catch(Exception ey)
This code was actually adopted from an NIIT Manual that i had wayback 2006 when i was a complete newbie to java. Now i intend trying out the RMI samples i have in the manual. But i feel there is something i'm missing. I'm not sure if there should a restructuring of this code due to API enhancements or anything else. I'm appreciate a rapid response...

Olakunle Oladipo Oni
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 37884
Question too difficult for “beginning”: moving.
Sujeeth Pakala
Ranch Hand

Joined: Mar 24, 2009
Posts: 94
Your code snippet is more about swing GUI. Question not clear, please rephrase it sorry !

Regards, Sujeeth Pakala
SCJP, SCWCD, SCBCD, ICAD, XML Master Basic, Certified SOA Professional
It is sorta covered in the JavaRanch Style Guide.
subject: RMI application connection issue
Similar Threads
creating file in documents folder
trouble with my gui
trouble with my table
getting a table to refreshing upon clicking button
mysql refused rmi connection