aspose file tools*
The moose likes Distributed Java and the fly likes mysql refused rmi connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "mysql refused rmi connection " Watch "mysql refused rmi connection " New topic
Author

mysql refused rmi connection

leon ting
Greenhorn

Joined: Apr 11, 2004
Posts: 18
who would kind enough to help me debug this:thanks a lot!
wrong hint: java.rmi.connectionexception:connection refused to host:169.254.176.230; nested exception is: java.net.connectException:connection refused:connect
db:test
table_name:registeration
table_field: firstName,lastName,address,phone,income,accountType
source code:
//-------------1.(interface) AccountServer.java:-----------------/
import java.rmi.*;
public interface AccountServer extends Remote{
String insertDetails(String firstName,String lastName,
String address,String phone,String income,String
accountType) throws RemoteException;
}
//-----------------------------------------------------------------/
//-------------2.(server) AccountServerImpl.java:-----------------/
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.sql.*;
public class AccountServerImpl extends UnicastRemoteObject implements AccountServer{
static ResultSet result;
static Connection conn;
static PreparedStatement stat;

public AccountServerImpl() throws RemoteException{
super();
}

public String insertDetails(String firstName,String lastName,
String address,String phone,String income,String
accountType) throws RemoteException{
int rowsAffected = 0;
String sReturn = "fail";
try{
int income1 = Integer.parseInt(income);
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/test?user=root&password=''&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);
stat = conn.prepareStatement("insert registration values(?,?,?,?,?,?)");
stat.setString(1,firstName);
stat.setString(2,lastName);
stat.setString(3,address);
stat.setString(4,accountType);
stat.setInt(5,income1);
stat.setString(6,phone);

rowsAffected = stat.executeUpdate();

if(rowsAffected>0) return "sucess";
}catch(Exception v){System.out.println("error at value insert" + v);}
return sReturn;
}
public static void main(String[] args){
try{
AccountServerImpl instance = new AccountServerImpl();
Naming.rebind("AccountServer",instance);
System.out.println("Server Registered");
}catch(Exception e){System.out.println(e);}
}
}
//------------------------------------------------------------------------/
//-------------3.(Client) Client.java:------------------------------------/
import javax.swing.*;
import java.rmi.*;
import java.awt.event.*;
import java.awt.*;
public class Client
{
static JFrame frame;
static JPanel panel;
static JPanel panel1;
JLabel labelFirstName;
JLabel labelLastName;
JLabel labelAddress;
JLabel labelPhone;
JLabel labelIncome;
JLabel labelAccountType;
JTextField textFirstName;
JTextField textLastName;
JTextField textAddress;
JTextField textPhone;
JTextField textIncome;
JComboBox AccountType;
JButton submit;
static String firstName;
static String lastName;
static String address;
static String phone;
static String income;
static String accountType;
public Client(){
panel= new JPanel();
panel1= new JPanel();
panel.setLayout(new GridLayout(6,2));
panel1.setLayout(new GridLayout(1,1));
frame = new JFrame("Earnest Bank");
frame.setVisible(true);
frame.setSize(400,200);
frame.getContentPane().setLayout(new BorderLayout());
labelFirstName= new JLabel("First Name");
labelLastName= new JLabel("Last Name");
labelAddress= new JLabel("Address");
labelPhone= new JLabel("Phone");
labelIncome= new JLabel("Annual Income");
labelAccountType = new JLabel("Account type");
textFirstName= new JTextField(30);
textLastName= new JTextField(30);
textAddress= new JTextField(30);
textPhone= new JTextField(30);
textIncome= new JTextField(30);
submit= new JButton("Submit");
String[] Type= {"Savings","Current"} ;
AccountType= new JComboBox(Type);
panel.add(labelFirstName);
panel.add(textFirstName);

panel.add(labelLastName);
panel.add(textLastName);
panel.add(labelAddress);
panel.add(textAddress);
panel.add(labelIncome);
panel.add(textIncome);
panel1.add(submit);
ButtonListener blisten = new ButtonListener();
submit.addActionListener(blisten);
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;

try{
AccountServer server = (AccountServer)Naming.lookup("rmi://localhost/AccountServer");
firstName= textFirstName.getText();
lastName= textLastName.getText();
address= textAddress.getText();
phone= textPhone.getText();
income= textIncome.getText();
accountType= (String)AccountType.getSelectedItem();
String str= server.insertDetails(firstName,lastName,address,phone,income,accountType);
System.out.println(str);
if(str.equals("success"))myDialog = new MyDialog(frame,"Inserted Successfully");
elsemyDialog = new MyDialog(frame,"Inserted failed");
myDialog.setVisible(true);
}
catch(Exception e){System.out.println(e);}
}
}
public static void main(String args[]){
new Client();
}
class MyDialog extends Dialog implements ActionListener
{
MyDialog(Frame parent, String title){
super(parent,title,false);
setLayout(new FlowLayout());
setSize(200,80);
add(new JLabel(title));
JButton btn_OK= new JButton("OK");
add(btn_OK);
btn_OK.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
dispose();
}
}
}
//-----------------------------------------------------------------/
[ April 27, 2004: Message edited by: leon ting ]
[ April 27, 2004: Message edited by: leon ting ]
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
in your naming.rebind() call, instead of localhost, use 127.0.0.1 . it sounds like localhost is actually giving you your computer's ip address instead of the loopback address.

HTH
Chris
leon ting
Greenhorn

Joined: Apr 11, 2004
Posts: 18
Originally posted by Chris Shepherd:
in your naming.rebind() call, instead of localhost, use 127.0.0.1 . it sounds like localhost is actually giving you your computer's ip address instead of the loopback address.

HI CHRIS:
i guess it's a mysql connection problem not a rebind/lookup reason, for i'm weak of mysql, any suggestion?
with great respect
[ April 27, 2004: Message edited by: leon ting ]
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
Did you try the loopback address? Did it change anything?
leon ting
Greenhorn

Joined: Apr 11, 2004
Posts: 18
i haved tried loopback address, doesn't work, same problem
[ April 28, 2004: Message edited by: leon ting ]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

When you get an exception, where is the exception originating? Is it a problem with the client calling the server, or is it a problem with the server making a connection to the database?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
The thing is, it doesn't look like a database error you are getting. It looks like a network error. Any chance of getting a printStackTrace() from the error instead of just the main error? That plus the answer to Nathan's question might give us more clues.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mysql refused rmi connection