Download presentation
Presentation is loading. Please wait.
Published byMeghan Holmes Modified over 9 years ago
1
Tasks Needed for MissionMapEditor Martin Q. Zhao September 18, 2010
2
DB Connectivity In MMEditor Provide high level functions Provide query level functions Encapsulate JDBC constructs: Driver, Connection, Statement
3
DAO JDBC Framework DB Table DBMS Application (client) DB Server Driver Connection Statement ResultSet creates executes returns java.sql MMEditor MySQL Server Instance mysql-connector.jar implements
4
New DB Functions 4 MMEditor Add updateMapToDb Add updateMission deleteMission Similar design can be used in VulnerabilityTracker
5
Sample JDBC Code Get connection to DB server Run query and process results // set driver String driverName = "com.mysql.jdbc.Driver"; try { Class.forName(driverName); } catch (ClassNotFoundException e) { } // get connection urlBase = "jdbc:mysql://localhost:3306/“ try { conn = DriverManager.getConnection(urlBase + dbName, user, pwd); } catch (SQLException e) {} // get statement, which embodies queries try { stmt = conn.createStatement(); } catch (SQLException e) {} Driver Connection Statement ResultSet creates executes returns java.sql
6
Sample JDBC Code - continued Execute update commands Run query and process results // execute an insert statement String insertCommand = "INSERT INTO Mission VALUES ("; insertCmd += m.getId() + ", '" + m.getName() +"', null, 1, " + lookupMissionId(m.getType()) + ",1"; insertCommand += ")"; int rowsAffected = 0; try { rowsAffected = stmt.executeUpdate(insertCmd); } catch (SQLException e) {} // execute an select query String query = "SELECT SubMissionId FROM MissionSubMissionMap "+ "WHERE MissionId = " + parentMissionId; LinkedList ids = new LinkedList (); try { ResultSet rs = stmt.executeQuery(query); while (rs.next()) { ids.addLast(rs.getLong(1)); } } catch (SQLException e) {}
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.