Code example for PreparedStatement

Methods: close, executeUpdate, getGeneratedKeys, setInt, setString

0
		PreparedStatement ps = con
				.prepareStatement(
						"insert into document(nclStateMachine_idnclStateMachine,id) values (?,?)", 
						Statement.RETURN_GENERATED_KEYS);
 
		ps.setInt(1, obj.getIteractions().get(i).getNclMachine()
				.getIdnclStateMachine()); 
		ps.setString(2, obj.getIteractions().get(i).getNclMachine()
				.getDocuments().get(j).getId());
 
		ps.executeUpdate();
 
		ResultSet rskey = null;
		rskey = ps.getGeneratedKeys();
 
		if (rskey != null && rskey.next()) {
			obj.getIteractions().get(i).getNclMachine().getDocuments().get(j)
					.setIddocument(rskey.getInt(1));
		} 
 
		ps.close();
		con.close();
	} 
}