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 ]