This discussion is archived
1 Reply Latest reply: May 23, 2011 11:47 PM by EJP RSS

RMI newbeee

863829 Newbie
Currently Being Moderated
Can anyone try to see why I'm getting a million errors. The method worked fine when executed in another page without any RMI stuff and remoteexceptions...

I'd appreciate any help
thanks
Mario


=======================
package server;


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

import java.util.*;


import interfacee.serverinterface;

public class databasemethods extends UnicastRemoteObject implements serverinterface
{
     

public databasemethods() throws java.rmi.RemoteException
{}

     public String withdraw(int id, int amount) throws RemoteException
     {      
          
     PreparedStatement ps = null;
               Statement stmt = null;
     
     //Load Driver
               Class.forName("com.mysql.jdbc.Driver");
//Make a connection
     Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/bank", "root", "");
//Create a Statement
     stmt = conn.createStatement();
//Execute a query
     ResultSet rs = stmt.executeQuery("SELECT id, uid, balance FROM accounts WHERE id="+id+"");
//Browse result
     System.out.println("ID\t-CLIENT-\t-Credit-\t-BALANCE");
     while (rs.next())
     {
     //id
          System.out.print(rs.getString(1));
     //uid
     System.out.print("\t" + rs.getString(2));
                         
     System.out.print("\t" + amount);
     //BALANCE
     int b= rs.getInt("balance");
     int newbalance = b-amount;
     System.out.print("\t\t" + newbalance );

     ps = conn.prepareStatement("update accounts set balance = "+newbalance+" where id = "+id+"");
     ps.executeUpdate();

     stmt.close();
conn.close();

     }
     return null;           
}
========================

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points