Title: Milestone 2 Hints
1Milestone 2 Hints
- MIE456 - Information Systems Infrastructure II
- Vinod Muthusamy
- November 11, 2004
2Component interactions
GUI
Server
Database
RMI
JDBC
3Relevant classes
- ApptRepositoryMySQL
- Write JDBC calls
- Pass object to ApptControllerServer
- ApptControllerServer
- Write yourself (use reference solution from M1)
- Make it a remote object
- Generate stub to be used by client
- ApptControllerClient
- Get reference to remote ApptControllerServer
object - Pass object to CalGrid
- CalGrid
- Given
Database
Server
Client
ApptControllerServer ApptRepositoryMySQL
CalGrid ApptControllerClient
RMI
JDBC
4Server ApptRepositoryMySQL
public class ApptRepositoryMySQL extends
ApptRepository public void RemoveUser(User
u) str DELETE FROM users WHERE userid
u.ID stmt.executeUpdate(str)
Database
Server
Client
ApptControllerServer ApptRepositoryMySQL
CalGrid ApptControllerClient
RMI
JDBC
5Server ApptControllerServer
public class ApptControllerServer extends
UnicastRemoteObject implements ApptController
public ApptControllerServer() throws
RemoteException try System.setSecurityMan
ager(new RMISecurityManager()) ApptControllerS
erver server new ApptControllerServer (new
ApptRepositoryMySQL()) Naming.rebind(APPTSERV
ER" , server) catch ()
Database
Server
Client
ApptControllerServer ApptRepositoryMySQL
CalGrid ApptControllerClient
RMI
JDBC
6Client ApptControllerClient
public class ApptControllerClient public static
void main(String args) System.setSecurityMa
nager(new RMISecurityManager()) try
ApptControllerServer server (ApptController
Server )Naming.lookup(url) CalGrid grid new
CalGrid(server) catch ()
Database
Server
Client
ApptControllerServer ApptRepositoryMySQL
CalGrid ApptControllerClient
RMI
JDBC
7Suggested steps
- RMI connection between client/server
- Write ApptControllerServer
- Most of the code is given
- Make it remotable
- Register server object with RMI registry
- Use ApptMemoryBased as the database for now
- ApptControllerServer server new
ApptControllerServer (new ApptMemoryBased()) - Generate server stub/skeleton
- Write ApptControllerClient
- Get reference to remote server object
- Pass object to CalGrid
8Suggested steps (2)
- JDBC database calls
- Write ApptRepositoryMySQL
- Write implementation for functions in
ApptRepository interface - Test your SQL statements first in MySQL Query
Browser - Now use ApptRepositorMySQL as the database
- ApptControllerServer server new
ApptControllerServer (new ApptRepositoryMySQL())
9JDBC prepared statements
- Allows precompilation of SQL statements
- Simple interface to set SQL parameters
10JDBC prepared statements (2)
DELETE FROM users WHERE userid bob
Without prepared statement
public void RemoveUser(User u) Statement stmt
conn.createStatement() str DELETE FROM
users WHERE userid u.ID
stmt.executeUpdate(str)
With prepared statement
public void RemoveUser(User u) str DELETE
FROM users WHERE userid ? PreparedStatement
stmt conn.prepareStatement(str) stmt.setString(1
, u.ID) stmt.executeUpdate()